time.h
Prototype
extern int _daylight;
Description
This variable is used in the time functions. It is set to non-zero by _tzset if a daylight savings time zone is specified in the TZ environment variable, otherwise it is set to zero. The default is 1.
Synonym
Variable: daylight
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
time.h
Prototype
double difftime (time_t time2, time_t time1);
Description
difftime subtracts time1 from time2 to calculate the time
elapsed between time1 and time2. The value is calculated in
seconds elapsed. The arguments are normally obtained by two calls
to the time function.
Return Value
Returns the difference between time1 and time2 in seconds.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
asctime
clock
ctime
gmtime
localtime
mktime
time
Example
/* Example for difftime Also demonstrates time */ #include <stdio.h> #include <stdlib.h> #include <time.h> void main() { int count; time_t start, finish; time (& start); for (count = 1; count <= 5000; count++) { printf ("%d\r", count); } time (& finish); printf("\nCounting to 5000 took %.2f seconds", difftime (finish, start)); }Output
5000
Counting to 5000 took 3.00 seconds
sys\timeb.h
Prototype
void _ftime(struct _timeb *timeptr);
Description
The _ftime function gets the current time and copies it to the structure pointed to by the timeptr argument. Fields of the _timeb structure are:
Function: ftime Structure: timeb
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example program for _ftime */ #include <stdlib.h> #include <stdio.h> #include <time.h> #include <sys\timeb.h> void main () { struct timeb t; putenv ("TZ= PST8PDT"); tzset (); ftime(& t); printf ("The difference between local time and GMT is %d minutes\n", t.timezone); }Output
The difference between local time and GMT is 480 minutes
time.h
Prototype
char *_strdate(char *datestr);
Description
The _strdate function converts the current date to a null-terminated string and stores it in the buffer pointed to by the datestr argument. The date string has the following format:
mm/ dd/ yy
where mm represents the month (01 for January), dd represents the day (01 for the first), and yy indicates the year (93 for 1993).
Return Value
A pointer to the date string.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of _strdate Also demonstrates _strtime */ #include <stdio.h> #include <stdlib.h> #include <time.h> void main () { char datestr[9], timestr[9]; _strdate(datestr); _strtime(timestr); printf ("The current date and time is %s on %s\n", timestr, datestr); }Output
The current date and time is 11: 07: 58 on 06/ 23/ 94
time.h
Prototype
extern long _timezone;
Description
This variable provides the difference in seconds between local time and Coordinated Universal Time. The default is 28, 000 seconds.
Synonym
Variable: timezone
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
time.h
Prototype
extern char *_tzname[2];
Description
This variable is an array of two strings containing the following time
zone names, whose string values are derived from the TZ
environment variable:
tzname[0] Three-letter time zone name. tzname[1] Three-letter daylight savings time zone name, or empty string if TZ omits daylight savings time zone.
Variable: tzname
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
time.h
Prototype
void _tzset(void);
Description
The _tzset function uses the current setting of the TZ environment variable to set global variables: _daylight, _timezone, and _tzname. These variables are used by the _ftime, localtime, and time functions.
To set the TZ environment variable from DOS, use the command:
set TZ = tzn[+ | -] hh[: mm[: ss]]][dzn]
tzn represents a time zone, such as PST (Pacific Standard Time) or EST (Easter Standard Time).hh represents an offset, in hours, from the UTC (Coordinated Universal Time). The hours can be followed by minutes and seconds (mm and ss). The dzn represents daylight savings time zone, such as PDT (Pacific Daylight Time).
When _tzset is called, the following values are assigned to _daylight, _timezone, and _tzname are:
° _daylight receives a non-zero value if a daylight-saving- time zone is specified in the TZ variable; otherwise receives zero.
° _timezone receives the difference, in seconds, between UTC and local time
° _tzname receives the string value of the daylight-saving-time zone or an empty string if this zone is omitted.
Synonym
Function: tzset
Variables: timezone, daylight, tzname
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example program for _tzset */ #include <stdlib.h> #include <stdio.h> #include <time.h> void main () { time_t curtime; putenv ("TZ= PST8PDT"); tzset (); time (& curtime); printf ("Current time is %s\n", asctime(localtime(&curtime))); }Output
Current time is Fri Jun 24 15: 04: 49 1994
sys\types.h
sys\utime.h
Prototype
int _utime(char *filename, struct _utimbuf *times);
Description
The _utime function changes the modified time associated with the file specified by the filename argument. The times argument contains the new time to be applied to the file.
The times argument is a pointer to a _utimbuf structure, defined in sys\utime.h as:
time_t actime;
time_t modtime;
Although the structure contains a field for access time, only the modification time is set with DOS.
If the times argument is NULL, the current time will be used.
Return Value
_utime returns a 0 on success. If an error occurrs, -1 is returned and errno is set to EACCES (path name specifies directory or read-only file), EINVAL (invalid argument), EMFILE (too many open files), or ENOENT (file or path name not found).
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for _utime */ #include <stdio.h> #include <stdlib.h> #include <sys\utime.h> void main (int argc, char *argv[]) { if (argc != 2) { printf ("Usage: _utime [filename.ext]\n"); exit (EXIT_FAILURE); } if (_utime (argv[1], NULL) == -1) { perror ("Unable to update file"); exit (EXIT_FAILURE); } }Output
C:\SC\EXAMPLES> dir _utime. exe Volume in drive C is DIGIMARS Volume Serial Number is 1CD4-5ECB Directory of C:\SC\EXAMPLES _UTIME EXE 14,084 06-27-94 11: 02a 1 file(s) 14,084 bytes 100,917,248 bytes free C:\SC\EXAMPLES>_utime _utime. exe C:\SC\EXAMPLES> dir _utime. exe Volume in drive C is DIGIMARS Volume Serial Number is 1CD4-5ECB Directory of C:\SC\EXAMPLES _UTIME EXE 14,084 06-27-94 11: 10a 1 file(s) 14,084 bytes 100,917,248 bytes free
time.h
Prototype
char *asctime(const struct tm *ntime);
Description
asctime converts a time structure into an ASCII string of 26
characters including the null having the form of:
DDD MMM dd hh: mm: ss YYYY\n\0
The method of obtaining the time is to first call the time function to get the number of seconds elapsed since 00: 00: 00 GMT on January 1, 1968. This is passed as an argument to the localtime function which returns a pointer to the structure tm as defined in time.h. This is then used as the ntime argument to asctime.
Return Value
Returns a pointer to a character string containing the date and time. The string is static and is overwritten with each call to asctime.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
clock
ctime
difftime
localtime
Example
/* Example of asctime Also demonstrates localtime */ #include <stdio.h> #include <stdlib.h> #include <time.h> void main() { time_t encoded_time; struct tm *decoded_time; char* time_string; encoded_time = time(NULL); decoded_time = localtime(&encoded_time); time_string = asctime(decoded_time); printf ("Current date and time: %s\n", time_string); }Output
The output will be similar to :
Current date and time: Mon Jun 20 14: 26: 25 1994
time.h
Prototype
clock_t clock(void)
Description
The clock function determines the time elapsed since the calling program started, in hundreths of a second. clock estimates the time elapsed using the system clock; it is only as accurate as the system clock. For example, the IBM PC timer granularity is 1/ 18th of a second, so the value returned by clock is accurate to 1/ 18th of a second despite a return value adjusted to hundreths of a second.
Return Value
A clock_t value representing the time, in 1/ 100ths of a second, used thus far by the calling program, where clock_t is a long integer. Divide the return value by the constant CLOCKS_PER_SEC to estimate the time elapsed in seconds. If the processor time used is unavailable or unrepresentable, -1 is returned.
See Also
asctime
ctime
difftime
localtime
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* Example for clock */ #include <stdio.h> #include <stdlib.h> #include <time.h> void main() { clock_t time_elapsed; float time_in_seconds; int count; for (count = 1; count <= 5000; count++) { printf ("%d\r", count); } time_elapsed = clock(); time_in_seconds = (float) time_elapsed / CLOCKS_PER_SEC; printf ("\nclock() returned %ld after counting to 5000\n", time_elapsed); printf ("which is %. 2f seconds\n", time_in_seconds); }Output
5000
clock() returned 2530 after counting to 5000
which is 2.53 seconds
char *ctime(const time_t *ntime);
DDD MMM dd hh:mm:ss YYYY\n\0Where:
DDD day of the week MMM month dd day of the month hh:mm:ss hour:minutes:seconds YYYY year
/* Example for ctime */ #include <stdio.h> #include <stdlib.h> #include <time.h> void main() { time_t encoded_time; char *time_string; time (& encoded_time); time_string = ctime(&encoded_time); printf("The current date and time: %s\n", time_string); }
The current date and time: Tue Jun 21 15:27:23 1994
time.h
Prototype
struct tm *gmtime(const time_t *timer);
Description
The gmtime function converts the value pointed to by argument timer to a structure, tm. The timer value is the time in seconds elapsed since midnight, January 1, 1968 (UTC).
The tm structure stores the timer value in the following int fields:
Return Value
A pointer to the structure. Returns NULL if timer is before midnight, January 1, 1968 UTC.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
asctime
ctime
_ftime
localtime
mktime
time
Example
/* Example for gmtime Also demonstrates localtime */ #include <time.h> #include <stdio.h> void main () { time_t the_time; time (& the_time); printf ("Coordinated Universal Time is %s", asctime (gmtime (& the_time))); printf ("Local Time is %s", asctime (localtime (& the_time))); }Output
Coordinated Universal Time is Thu Jun 23
23: 40: 07 1994
Local Time is Thu Jun 23
16: 40: 07 1994