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
 
Back
Top