Custom Format for Current Date and Time in C++
I am trying to save a file into a directory of files ba开发者_开发百科sed on the current date and time. I am trying to get the format of the following:
- "FullMonth-FullYear" example: "April-2011"
- "FullMonth-littleDay-year" example: "March-7-11"
- hour-minutes-seconds. example: "18:05:09" in 24 hour format
It depends on the format you have the time in right now. I'm a big fan of sprintf()
, and since I mostly deal with big piles of seconds, milliseconds, or nanoseconds, I do a lot of modulus arithmetic to get what I want.
boost.date_time can do arbitrary formatting, to a higher a degree of precision than the standard functions are typically capable of. Specifically, see Date Time Input/Output Format Flags.
精彩评论