Time zone conversion C API on Linux, anyone?

后端 未结 6 1269
终归单人心
终归单人心 2020-12-29 03:40

I\'m looking for something that I presumed would be very simple - given local Unix time in a specific time zone (specified as a string, e.g., \"America/New_York\" - note tha

6条回答
  •  误落风尘
    2020-12-29 03:57

    Similar to the Python answer, I can show you what R does:

    R> now <- Sys.time()       # get current time
    R> format(now)             # format under local TZ
    [1] "2009-08-03 18:55:57"
    R> format(now,tz="Europe/London")   # format under explicit TZ
    [1] "2009-08-04 00:55:57"
    R> format(now,tz="America/Chicago") # format under explicit TZ
    [1] "2009-08-03 18:55:57"
    R> 
    

    but R uses an internal representation that extends the usual struct tm --- see R-2.9.1/src/main/datetime.c.

    Still, this is a hairy topic and it would be nice if it were the standard library. As it isn't maybe your best bet is to use Boost Date_Time (example)

提交回复
热议问题