Luron
Luron

Reputation: 1187

Custom Format for Current Date and Time in C++

I am trying to save a file into a directory of files based on the current date and time. I am trying to get the format of the following:

  1. "FullMonth-FullYear" example: "April-2011"
  2. "FullMonth-littleDay-year" example: "March-7-11"
  3. hour-minutes-seconds. example: "18:05:09" in 24 hour format

Upvotes: 2

Views: 600

Answers (2)

ildjarn
ildjarn

Reputation: 62975

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.

Upvotes: 0

pattivacek
pattivacek

Reputation: 5823

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.

Upvotes: 1

Related Questions