Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

x86 - How to set (or correct for) timezone & DST in c (time.h functions) and DOS

I have a computer running DOS (freeDos 1.1) and plain C (compiled with Borland 5.0) with time.h. When I set the computer time using BIOS or the DATE and TIME DOS commands, there is no information about time zone. I set the time to my current time 10:25 AM.

My C program does this...

char timeString[80];
time_t timeT = time(NULL);
strftime(timeString, sizeof(timeString), "%a %Y-%m-%d %H:%M:%S %Z", localtime(&timeT));
printf("%s
", timeString);

when I run the code I get the correct current time but with a "EST" time zone at the end as called by the %Z formatter.

Mon 2017-03-13 10:25:36 EST

The returned time_t value from time(NULL) is 1489418736.
This mathematically breaks down to 47 years, 83 days, 15 hours, 25 minutes, 36 seconds
Clearly time.h is implementing some time zone information here, adding 5 hours to my current time.

Moving over to javascript which receives the time_t value

new Date(1489418736 * 1000)

Mon Mar 13 2017 08:25:36 GMT-0700 (Pacific Daylight Time)

It seems there is some combination of time zone (EST vs PST vs GMT) and daylight savings time (which might account for the extra hour?) at play here. How can I affect the time zone and DST settings of the machine, operating system, or C library representation, to get the most useful time representation whether that be local or GMT?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...