2015-10-08 38 views
1

任何想法爲什麼這是返回非日期時間,而不是時間字符串?我在Ubuntu 15.04使用升壓1.55.0.2boost posix_time:stringstream輸入失敗

#include <iostream> 
#include "boost/date_time/posix_time/posix_time.hpp" 

using namespace boost::posix_time; 

int main(int argc, char **argv) { 

    ptime t2; 
    std::stringstream ss("2004-Jan-1 05:21:33.20"); 
    ss >> t2; 

    std::cout<<t2<< std::endl; 

    return 0; 
} 

回答

1

你想要的「簡單的字符串」格式YYYY-mmm-DD HH:MM:SS.fffffffff

查看posix time docs

當天是兩位數,所以請用std::stringstream ss("2004-Jan-01 05:21:33.20");代替。

Live on coliru!

+0

正確,謝謝。我從boost文檔中直接拉出該字符串,所以沒有打擾檢查。 http://www.boost.org/doc/libs/1_55_0/doc/html/date_time/examples/general_usage_examples.html – dmagree

+0

某處是否有可接受的格式列表? posix時間文檔不清楚。例如,它看起來像YYYY-MM-DD HH:MM:SS.fffffffff也可以接受給定的例子,但它也不適用於我。 – dmagree

+0

我認爲三個to_string轉換格式是可以接受的,非常簡單,iso和iso_extended。因此'YYYY-MM-DD HH:MM:SS.fffffffff'不會被接受,但是'YYYY-MM-DDTHH:MM:SS,fffffffff'會。 – slaphappy