Convert UTC Milliseconds to DATETIME in SQL server
DECLARE @UTC BIGINT SET @UTC = 1348203320997 SELECT DATEADD(MILLISECOND, @UTC % 1000, DATEADD(SECOND, @UTC / 1000, ‘19700101’))
DECLARE @UTC BIGINT SET @UTC = 1348203320997 SELECT DATEADD(MILLISECOND, @UTC % 1000, DATEADD(SECOND, @UTC / 1000, ‘19700101’))
In (the current) CPython time.time() calls floattime(NULL) which calls _PyTime_gettimeofday_info() which calls pygettimeofday() where pygettimeofday() may use GetSystemTimeAsFileTime(), clock_gettime(CLOCK_REALTIME), gettimeofday() functions depending on the platform. Unrelated: time.time() returns “seconds since the epoch”. It is POSIX time on most systems supported by Python (Linux, OS X, Windows). POSIX timestamp is not the number of elapsed SI … Read more
If you can assume POSIX (and thus the POSIX specification of time_t as seconds since the epoch), I would first use the POSIX formula to convert to seconds since the epoch: tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 – ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 Next, use localtime((time_t []){0}) to get a struct tm … Read more
Use the Date.UTC() method: var TheDate = new Date( Date.UTC(2012, 10, 5) ); console.log( TheDate.toUTCString() ); returns Mon, 05 Nov 2012 00:00:00 GMT Date.UTC Accepts the same parameters as the longest form of the constructor, and returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.
PHP’s DateTime object is pretty flexible. $UTC = new DateTimeZone(“UTC”); $newTZ = new DateTimeZone(“America/New_York”); $date = new DateTime( “2011-01-01 15:00:00”, $UTC ); $date->setTimezone( $newTZ ); echo $date->format(‘Y-m-d H:i:s’);
The OP answered this question to change the default timezone for a single instance of a running JVM, set the user.timezone system property: java -Duser.timezone=GMT … <main-class> If you need to set specific time zones when retrieving Date/Time/Timestamp objects from a database ResultSet, use the second form of the getXXX methods that takes a Calendar … Read more
Short answer: you can’t. Daylight saving time make it impossible. For example, there is no way to determine, solely from UTC offset, the difference between Arizona and California in the summer, or Arizona and New Mexico in the winter (since Arizona does not observe DST). There is also the issue of what time different countries … Read more
Java: int offset = TimeZone.getDefault().getRawOffset() + TimeZone.getDefault().getDSTSavings(); long now = System.currentTimeMillis() – offset; Kotlin: val offset: Int = TimeZone.getDefault().rawOffset + TimeZone.getDefault().dstSavings val now: Long = System.currentTimeMillis() – offset
I would use my Noda Time project personally. (Admittedly I’m biased as the author, but it would be cleaner…) But if you can’t do that… Either use DateTime.ParseExact specifying the exact format you expect, and include DateTimeStyles.AssumeUniversal and DateTimeStyles.AdjustToUniversal in the parse code: using System; using System.Globalization; class Test { static void Main() { var … Read more
I think I got it: pytz.utc.localize(utc_time, is_dst=None).astimezone(tz) This line first converts the naive (time zone unaware) utc_time datetime object to a datetime object that contains a timezone (UTC). Then it uses the astimezone function to adjust the time according to the requested time zone.