How does python’s time.time() method work?

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

How to convert from UTC to local time in C?

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

create javascript date UTC

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.

UTC Date/Time String to Timezone

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’);

Force Java timezone as GMT/UTC

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

DateTime.Parse(“2012-09-30T23:00:00.0000000Z”) always converts to DateTimeKind.Local

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