E
E
Evengard2012-01-06 21:11:38
ISO
Evengard, 2012-01-06 21:11:38

Get ISO 8601 in C++ using WinAPI?

Actually, subject. I need to get the current time in Windows and display it in ISO 8601 format. What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evengard, 2012-01-06
@Evengard

It turned out something like this:

char* dateTime[22];
DYNAMIC_TIME_ZONE_INFORMATION tz;
SYSTEMTIME time;
GetLocalTime(&time);
GetDynamicTimeZoneInformation(&tz);
char timeZone[7];
if(tz.Bias==0)
  strcpy(timeZone, "Z");
else
{
  char symbol=(tz.Bias>0)?('-'):('+');
  u_int tzHours = floor((long double)(abs(tz.Bias)/60));
  u_int tzMinutes = abs(tz.Bias)%60;
  sprintf(timeZone, "%c%02u:%02u", symbol, tzHours, tzMinutes);
}
char timeStamp[22];
sprintf(timeStamp, "%04i-%02i-%02iT%02i:%02i:%02i%s", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, timeZone);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question