The _gmtime64_s() and asctime_s() function C examples
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Target platform: none, just for learning
Header file: Standard and Windows
Additional library: Windows Platform SDK
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: non-CLR or unmanaged
To do: Converting the coordinated universal time to ascii string
To show: Using the _gmtime64_s() and asctime_s() C functions
// _gmtime64_s(): This program uses _gmtime64_s() to convert a 64-bit
// integer representation of coordinated universal time to a structure named newtime, then uses asctime_s() to convert this structure to an output string.
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm newtime;
__int64 ltime;
char buf[26];
errno_t err;
_time64(<ime);
// Obtain coordinated universal time:
err = _gmtime64_s(&newtime, <ime);
if (err)
{
printf("Invalid Argument to _gmtime64_s().");
}
// Convert to an ASCII representation
err = asctime_s(buf, 26, &newtime);
if (err)
{
printf("Invalid Argument to asctime_s().");
}
printf("Coordinated universal time is %s\n", buf);
}
Output example:
Coordinated universal time is Sun Dec 17 09:11:33 2006
Press any key to continue . . .