开发者

How to achieve this specific datetime format using boost?

I want to format a datetime like this:

YYYYMMDD_HHMMSS

eg, 4 digit year, followed by 2 digit months, followed by 2 digit day, underscore, 24-hour hour, 2 digit minutes, 2 digit seconds.

e.g.: 16th of February 2011, 8:05 am and 2 seconds would be:

20110216_080502

What format string should I use in the following code to achieve this? (And, if necessary, what code changes are needed):

//.开发者_运维问答..#includes, namespace usings...

ptime now = second_clock::universal_time();

wstringstream ss;
time_facet *facet = new time_facet("???"); //what goes here?
ss.imbue(locale(cout.getloc(), facet));
ss << now;

wstring datetimestring = ss.str();

Here are some strings I've tried so far:

%Y%m%d_%H%M%S : "2011-Feb-16 16:51:16"

%Y%m%d : "2011-Feb-16"

%H%M%S : "16:51:16"

Here's another one:

%Y : "2011-Feb-16 16:51:16" huh??


I believe you need to use wtime_facet, not time_facet. See the working program I posted on your other question.


From date/time facet format flags:

"%Y%m%d_%H%M%S"


  time_facet *facet = new time_facet("%Y%m%d_%H%M%S");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜