Convert LocalDateTime to LocalDateTime in UTC
I personally prefer LocalDateTime.now(ZoneOffset.UTC); as it is the most readable option.
I personally prefer LocalDateTime.now(ZoneOffset.UTC); as it is the most readable option.
Recently I have run into the same issue. And it was resolved using the following code: x = new Date(); let hoursDiff = x.getHours() – x.getTimezoneOffset() / 60; let minutesDiff = (x.getHours() – x.getTimezoneOffset()) % 60; x.setHours(hoursDiff); x.setMinutes(minutesDiff);
Using gmdate will always return a GMT date. Syntax is same as for date.
I would do it in PHP, except I would avoid doing preg_match 100 some times and do this to generate your list. $tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL); Also, I would use PHP’s names for the ‘timezones’ and forget about GMT offsets, which will change based on DST. Code like that in phpbb is only that way b/c … Read more
6/1/2011 4:08:40 PM Local 6/1/2011 4:08:40 PM Utc from DateTime dt = DateTime.Now; Console.WriteLine(“{0} {1}”, dt, dt.Kind); DateTime ut = DateTime.SpecifyKind(dt, DateTimeKind.Utc); Console.WriteLine(“{0} {1}”, ut, ut.Kind);
Astronomy versus Atomic clock By the original definitions the difference is that GMT (also officially known as Universal Time (UT), which may be confusing) is based on astronomical observations while UTC is based on atomic clocks. Later GMT has become to be used at least unofficially to refer to UTC, which blurs the distinction somewhat. … Read more
It seems that it does not matter what timezone is on the server as long as you have the time set right for the current timezone, know the timezone of the datetime columns that you store, and are aware of the issues with daylight savings time. On the other hand if you have control of … Read more
Here is the list of valid timezones: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones You can use TIME_ZONE = ‘Europe/Istanbul’ for UTC+02:00
Dates constructed that way use the local timezone, making the constructed date incorrect. To set the timezone of a certain date object is to construct it from a date string that includes the timezone. (I had problems getting that to work in an older Android browser.) Note that getTime() returns milliseconds, not plain seconds. For … Read more
If you want to convert a python datetime to seconds since epoch you could do it explicitly: >>> (datetime.datetime(2012,4,1,0,0) – datetime.datetime(1970,1,1)).total_seconds() 1333238400.0 In Python 3.3+ you can use timestamp() instead: >>> datetime.datetime(2012,4,1,0,0).timestamp() 1333234800.0 Why you should not use datetime.strftime(‘%s’) Python doesn’t actually support %s as an argument to strftime (if you check at http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior it’s … Read more