简体   繁体   中英

What are the disadvantages to using ctime's tzset?

In a question about getting a system's time zone, this answer did not get up-voted.

It suggests the use of tzset() and some system globals (eg daylight , timezone , and tzname ) from time.h .

After some testing, I was able to get accurate results from this method on both Windows and Mac. But I'm guessing the answer mentioned above was not up-voted for a reason. Is this true? Should I prefer OS-specific calls instead of this C-standard?

No, if there is not an standard C function (and you are programming to at least one POSIX compliant system) then you should use prefer POSIX functions over OS specific ones.

If one of your systems is not POSIX compliant, then you should have an OS specific solution only for that system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM