turugina #7516(2008/08/31 21:45 GMT) [ C++ ] Rating0/0=0.00
Boost.Date_Time で。 入出力の日付形式はコード中に書いてある通り(例:"2008-Sep-01 12:34:56")です。
see: Boost.Date_Time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <iostream> #include <string> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/lexical_cast.hpp> std::string DateEx( const std::string& dstr, int sec ) { using namespace boost::posix_time; return boost::lexical_cast<std::string>( ptime(dstr.empty() ? second_clock::local_time() : time_from_string(dstr) ) + seconds(sec) ); } int main(int c, char** v) { if ( c == 1 ) { std::cout << "usage: " << v[0] << " [<datetime{YYYY-Mon-DD hh:mm:ss}>] <seconds>\n"; return 0; } std::cout << DateEx( c>=3?v[1]:"", boost::lexical_cast<int>(c>=3?v[2]:v[1]) ) << "\n"; return 0; }
Rating0/0=0.00-0+
[ reply ]
turugina
#7516()
[
C++
]
Rating0/0=0.00
see: Boost.Date_Time
Rating0/0=0.00-0+
[ reply ]