I need to get timestamp in the following format that includes the timezone offset from UTC:
2014-03-07T10:03:50+02:00
I'm trying this approach but getting it as UTC without the timezone info formatted correctly:
time_t now;
time(&now);
char ts[sizeof "1970-01-01T00:00:00+00:00"];
strftime(ts, sizeof ts, "%FT%T%z", gmtime(&now));
printf("Timestamp: %s\n\n", ts);
And this is the result:
2014-03-07T09:29:40+0200
The JavaScript getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time. If the returned value is positive, local timezone is behind the UTC and if it is negative, the local timezone if ahead of UTC.
You cannot “ get a TimeZone ID from a certain TimeStamp”, that is impossible. Your count-from-epoch was made while accounting for a certain time zone, usually UTC. If must know that intended zone used in creating that count-from-epoch, it cannot be deduced.
You can get the current time in a particular timezone by using the datetime module with another module called pytz . You can then check for all available timezones with the snippet below: from datetime import datetime import pytz zones = pytz. all_timezones print(zones) # Output: all timezones of the world.
Breaking Down the Difference An offset is the number of hours or minutes a certain time zone is ahead of or behind GMT**. A time zone's offset can change throughout the year because of Daylight Saving Time. Sometimes laws change a time zone's offset or daylight savings pattern.
Man 7 strftime formats the time tm
according to the format specification format. And one of the format %z
outputs the numeric timezone by default as hhmm
without colon :
between hours and minutes,
%z
: The +hhmm
or -hhmm
numeric timezone (that is, the hour and minute offset from UTC). (SU)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With