Parse date and time in unmanaged C++

  • Thread starter Thread starter Bob Altman
  • Start date Start date
B

Bob Altman

Hi all,

I need to simulate current date and time and provide integer values for the
current year, month, day, hour, minute, second, and millisec. I need to do
this in unmanaged C++. My first inclination is to do roughly the same thing
that I would do in managed code: I would maintain a 64-bit integer value
that represents the number of millisec. (or nanosec.) since some date. I
would periodically increment this integer by the appropriate amount. My
question is, is there an unmanaged C/C++ function (maybe something buried in
the Windows API) that can perform the year/month/date conversion for me?
TIA!
 
Bob Altman said:
Hi all,

I need to simulate current date and time and provide integer values for the
current year, month, day, hour, minute, second, and millisec. I need to do
this in unmanaged C++. My first inclination is to do roughly the same thing
that I would do in managed code: I would maintain a 64-bit integer value
that represents the number of millisec. (or nanosec.) since some date. I
would periodically increment this integer by the appropriate amount. My
question is, is there an unmanaged C/C++ function (maybe something buried in
the Windows API) that can perform the year/month/date conversion for me?
TIA!

See the Win32 FILETIME and SYSTEMTIME structures and associated functions
like FileTimeToSystemTime. They do almost exactly what you describe above,
and can do additional things like time zone conversion, locale-specific
calendars, and more. I use them for all sorts of unmanaged date/time tasks.

Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top