Run-Time Library Reference
Time, _Time64
Get the system time.
Time_t Time
Time_t * Timer
);
__time64_t _time64 (
__time64_t * Timer
);
Parameters
Timer
Pointer to The Storage Location for Time.
Return Value
Return The Time in Elapsed Seconds. There is no error return.
A call to time or _time64 can fail, hoof, if the date passed to the function is:
Before Midnight, January 1, 1970. After 19:07, January 18, 2038, UTC (useing time and time_t). After 23:59:59, DECEMBER 31, 3000, UTC (useing _time64 and __time64_t).
Remarks
The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC), according to the system clock. The return value is stored in the location given by timer. This Parameter May Be Null, In Which Case The Return Value is not store
Requirements
Routinerequired headercompatibilitytime
For Additional Compatibility Information, See Compatibility In The Introduction.
Libraries
All Versions of The C Run-Time Libraries.
EXAMPLE
// CRT_TIMES.C
/ * This Program Demonstrates these Time and Date functions:
* _time64 _ftime64 _ctime64 asctime
* _LOCALTIME64 _GMTIME64 _MKTIME64 _TZSET
* _STRTIME _STRDATE STRFTIME
*
* Also The Global Variable:
* _tzname
* /
#include
#include
#include
#include
#include
int main ()
{
CHAR TMPBUF [128], AMPM [] = "AM";
__time64_t ltime;
Struct__timeb64 tstruct;
StructTM * Today, * GMT, Xmas = {0, 0, 12, 25, 11, 93}; / * set time zone from tz environment variable. if tz is not set,
* The Operating System Is Queried to Obtain The Default Value
* for the variable.
* /
_tzset ();
/ * Display Operating System-Style Date and Time. * /
_STRTIME (TMPBUF);
Printf ("OS TIME: / T / T / T / T% S / N", TMPBUF);
_STRDATE (TMPBUF);
Printf ("OS DATE: / T / T / T / T% S / N", TMPBUF);
/ * GET Unix-Style Time and Display As Number and String. * /
_Time64 (& ltime);
Printf ("TIME IN Seconds Since UTC 1/70: / T% LD / N", LTIME);
Printf ("Unix Time and Date: / T / T / T% S", _ctime64 (& ltime));
/ * Display utc. * /
GMT = _GMTIME64 (& ltime);
Printf ("Coordinated Universal Time: / T / T% S", ASCTIME (GMT));
/ * Convert to Time Structure and Adjust for PM if Necessary. * /
Today = _localtime64 (& ltime);
IF (Today-> TM_HOUR> = 12)
{
STRCPY (AMPM, "PM");
TODAY-> TM_HOUR - = 12;
}
IF (Today-> TM_HOUR == 0) / * adjust if midnight hours. * /
TODAY-> TM_HOUR = 12;
/ * Note How Pointer Addition Is Used to Skip The First 11
* CHARACTERS AND Printf is buy to Trim Off Terminating
* Characters.
* /
Printf ("12-hour time: /t/t/t/t%.8S% s / n",
Asctime (Today) 11, AMPM);
/ * Print Additional Time Information. * /
_ftime64 (& TSTRUCT);
Printf ("Plus MilliseConds: / T / T% u / n", tstruct.millitm;
Printf ("ZONE DIFCERENCE IN Hours from Utc: / T% U / N",
Tstruct.timezone / 60);
Printf ("Time Zone Name: / T / T / T% S / N", _TZNAME [0]);
Printf ("Daylight Savings: / T / T% S / N",
TSTRUCT.DSTFLAG? "YES": "no");
/ * Make Time For Noon on Christmas, 1993. * /
IF (_mktime64 (& xmas)! = (__time64_t) -1) Printf ("Christmas / T / T / T% S / N", asctime (& xmas));
/ * Use time structure to build a ready. * /
Today = _localtime64 (& ltime);
/ * Use strftime to build a customized time string. * /
StrfTime (TmpBuf, 128,
"Today is% a, day% d of% b in the yer% y. / N", today);
Printf (TMPBUF);
}
Sample Output
OS Time: 14:15:49
OS Date: 02/07/02
Time in Seconds Since UTC 1/1/70: 1013120149
UNIX Time and Date: Thu Feb 07 14:15:49 2002
Coordinated universal time: Thu Feb 07 22:15:49 2002
12-Hour Time: 02:15:49 PM
Plus Milliseconds: 455
ZONE DIFCERENCE IN Hours from UTC: 8
Time Zone Name: Pacific Standard Time
Daylight savings: no
Christmas Sat Dec 25 12:00:00 1993
Today Is Thursday, Day 07 of February In The Year 2002.