CAUTION: This sample program has been tested using DEC C v 6.5 on OpenVMS IA64 v 8.2. However, there is no guarantee for its effectiveness because of the possibility of error in transmitting or implementing the program. It is meant to be used as a template for writing your own program, and may require modification for use on your system.
This program is supported on the following systems:
Product: DEC C, all versions
Operating System: OpenVMS, v 7.3-2 and Above, HP Tru64 UNIX, v 5.1B PK4, HP-UX B.11.23
Details
PROGRAM NOTES:
An alternative to setting (setenv ) the environment variable TZ is to define the symbol TZ prior to running the program.
See description of procedure tzset() in the DEC C Run-Time Library Reference Manual for OpenVMS Systems.
NOTE: Defining TZ also impacts localtime , mktime , strftime and wcsftime functions. See the description of procedure tzset() in the HP C Run-Time Library Reference Manual for OpenVMS Systems .
Click here to view the HP C Run-Time Library Reference Manual for OpenVMS Systems.
Compilation, link and run:
$ cc/prefix=all time
$ link time
$ run time
PROGRAM:
/*
COPYRIGHT ©) 1998-2005 BY
HEWLETT-PACKARD COMPANY
ALL RIGHTS RESERVED.
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION
OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES
THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
SHOULD NOT BE CONSTRUED AS A COMMITMENT BY HEWLETT-PACKARD COMPANY.
HP ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY HP.
NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE
ON EQUIPMENT THAT IS NOT SUPPLIED BY HEWLETT-PACKARD COMPANY.
SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY HP SOFTWARE
PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE
CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.
*/
/*
With HPUX 11i V2 (B.11.23)
$ ./time
tzname[0] = MET, tzname[1] = METDST, daylight = 1, timezone = -3600
Local time is Tue Feb 1 08:39:04 2005
tzname[0] = MET, tzname[1] = MET_DST, daylight = 1, timezone = -3600
In France the time is Tue Feb 1 08:39:04 2005
tzname[0] = STD, tzname[1] = , daylight = 0, timezone = 0
GMT Time is Tue Feb 1 07:39:04 2005
With Tru64 V5.1B and OpenVMS V7.3-2
$ run time
tzname[0] = MET, tzname[1] = MET DST, daylight = 1, timezone = -3600
Local time is Tue Feb 1 08:49:46 2005
tzname[0] = MET, tzname[1] = MET_DST, daylight = 1, timezone = -3600
In France the time is Tue Feb 1 08:49:46 2005
tzname[0] = GMT, tzname[1] = , daylight = 0, timezone = 0
GMT Time is Tue Feb 1 07:49:46 2005
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main(){
time_t local_time;
char *pdat;
/*
* Get Universal Time Coordinates time.
*/
local_time = time(NULL);
/*
* Get the Local Time Zone environment variable.
*/
tzset();
printf ("tzname[0] = %s, tzname[1] = %s, daylight = %d, timezone = %d\n",
tzname[0],tzname[1],daylight,timezone);
pdat = ctime(&local_time);
printf ("Local time is %s\n",pdat);
/*
* Set the Standard Time Zone to -1 hour from GMT.
* The Daylight Savings Time Zone saving to -2 hours from GMT.
* date when change from standard time to summer time occurs on:
* 3nd of March at 2AM
* date when change from summer time to standard time occurs on:
* 5th of September at 3AM.
*/
#if defined (__unix)
putenv("TZ=MET-1MET_DST-2,M3.4.0/2,M10.5.0/3");
#elif defined (__VMS)
setenv ("TZ","MET-1MET_DST-2,M3.4.0/2,M10.5.0/3",0);
#endif
/*
* Get the French Time Zone environment variable.
*/
tzset();
printf ("tzname[0] = %s, tzname[1] = %s, daylight = %d, timezone = %d\n",
tzname[0],tzname[1],daylight,timezone);
pdat = ctime(&local_time);
printf ("In France the time is %s\n",pdat);
#if defined (__VMS)
unsetenv("TZ");
#endif
/*
* Reset TZ environment variable to GMT time.
*/
#if defined (__unix)
putenv ("TZ=GMT0");
#elif defined (__VMS)
setenv ("TZ","GMT0",0);
#endif
/*
* Get the GMT Zone environment variable.
*/
tzset();
printf ("tzname[0] = %s, tzname[1] = %s, daylight = %d, timezone = %d\n",
tzname[0],tzname[1],daylight,timezone);
pdat = ctime(&local_time);
printf ("GMT Time is %s\n",pdat);
#if defined (__VMS)
unsetenv("TZ");
#endif
}