OpenVMS Source-Code Demos

TIMEZONE_DEMO.C

/* ===================================================================
** title : TIMEZONE_DEMO.C
** author: unknown (published to newsgroup: comp.os.vms in 2011.05.xx)
** ===================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main (int argc, char *argv[])
{
	time_t t;
	typedef struct tm tm_t;
	tm_t *tml;
	tm_t *tmr;

	setenv ("TZ", "US/EASTERN", 1);
	tzset();
	t = time((time_t)0);
	tml = calloc( sizeof(tm_t), 1 );
	tmr = localtime_r(&t,tml);
	printf("US/EASTERN: %d-%02d-%02d-%02d:%02d:%02d.%03d\n",
		tml->tm_year+1900, tml->tm_mon+1, tml->tm_mday,
		tml->tm_hour, tml->tm_min, tml->tm_sec,
		(0));
	free(tml);

	setenv ("TZ", "JAPAN", 1);
	tzset();
	t = time((time_t)0);
	tml = calloc( sizeof(tm_t), 1 );
	tmr = localtime_r(&t,tml);
	printf("Japan: %d-%02d-%02d-%02d:%02d:%02d.%03d\n",
		tml->tm_year+1900, tml->tm_mon+1, tml->tm_mday,
		tml->tm_hour, tml->tm_min, tml->tm_sec,
		(0));
	free(tml);
}

Back to OpenVMS
Back to OpenVMS Demo Index
Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.