|
|
От: | LowCoder | |
| Дата: | 28.11.14 04:58 | ||
| Оценка: | |||
int64_t getSecondsFromDate( const std::string& strDate, const std::string& format )
{
namespace bpt = boost::posix_time;
typedef bpt::time_facet time_facet;
typedef bpt::ptime ptime;
bpt::time_facet* facet = new bpt::time_facet();
facet->format( format.c_str() );
std::stringstream ss( strDate.c_str() );
ss.imbue( std::locale(ss.getloc(), facet) );
bpt::ptime pt;
ss >> pt;
static bpt::ptime epoch( boost::gregorian::date(1970, 1, 1) );
bpt::time_duration diff( pt - epoch );
return diff.total_seconds();
}
...
std::string date1 = "20080501123045";
std::string date2 = "20080501134045";
std::string date3 = "20080501164045";
int64_t sec1 = getSecondsFromDate( date1, "%Y%m%d%H%M%S" );
int64_t sec2 = getSecondsFromDate( date2, "%Y%m%d%H%M%S" );
int64_t sec3 = getSecondsFromDate( date3, "%Y%m%d%H%M%S" );
std::cout << "Date1=" << sec1 << " Date2=" << sec2 << " Date3=" << sec3 << std::endl;
Output
Date1=2077252342 Date2=2077252342 Date3=2077252342|
|
От: | LowCoder | |
| Дата: | 28.11.14 05:24 | ||
| Оценка: | 1 (1) | ||
bpt::time_facet* facet = new bpt::time_facet();bpt::time_input_facet* facet = new bpt::time_input_facet();|
|
От: | omgOnoz | |
| Дата: | 29.11.14 20:36 | ||
| Оценка: | |||
| Скрытый текст | |
| LC>ОО! сам спросил и сам ответил — всегда приятно пообщатся с умным человеком LC> LC>на LC> LC>и все заработало LC>Тем не менне приветствуются любые комментарии | |
static bpt::ptime epoch( boost::gregorian::date(1970, 1, 1) );