Creating a DateTime in a specific Time Zone in c#

Jon’s answer talks about TimeZone, but I’d suggest using TimeZoneInfo instead. Personally I like keeping things in UTC where possible (at least for the past; storing UTC for the future has potential issues), so I’d suggest a structure like this: public struct DateTimeWithZone { private readonly DateTime utcDateTime; private readonly TimeZoneInfo timeZone; public DateTimeWithZone(DateTime dateTime, … Read more

How can I get the timezone name in JavaScript?

The Internationalization API supports getting the user timezone, and is supported in all current browsers. console.log(Intl.DateTimeFormat().resolvedOptions().timeZone) Keep in mind that on some older browser versions that support the Internationalization API, the timeZone property is set to undefined rather than the user’s timezone string. As best as I can tell, at the time of writing (July … Read more

Do UNIX timestamps change across timezones?

The definition of UNIX timestamp is time zone independent. The UNIX timestamp is the number of seconds (or milliseconds) elapsed since an absolute point in time, midnight of Jan 1 1970 in UTC time. (UTC is Greenwich Mean Time without Daylight Savings time adjustments.) Regardless of your time zone, the UNIX timestamp represents a moment … Read more

How to preserve timezone when parsing date/time strings with strptime()?

I recommend using python-dateutil. Its parser has been able to parse every date format I’ve thrown at it so far. >>> from dateutil import parser >>> parser.parse(“Tue Jun 22 07:46:22 EST 2010”) datetime.datetime(2010, 6, 22, 7, 46, 22, tzinfo=tzlocal()) >>> parser.parse(“Fri, 11 Nov 2011 03:18:09 -0400”) datetime.datetime(2011, 11, 11, 3, 18, 9, tzinfo=tzoffset(None, -14400)) >>> … Read more

How can I set the default timezone in node.js?

According to this google group thread, you can set the TZ environment variable before calling any date functions. Just tested it and it works. > process.env.TZ = ‘Europe/Amsterdam’ ‘Europe/Amsterdam’ > d = new Date() Sat, 24 Mar 2012 05:50:39 GMT > d.toLocaleTimeString() ’06:50:39′ > “”+d ‘Sat Mar 24 2012 06:50:39 GMT+0100 (CET)’ You can’t change … Read more

How do I get the current time zone of MySQL?

From the manual (section 9.6): The current values of the global and client-specific time zones can be retrieved like this: mysql> SELECT @@global.time_zone, @@session.time_zone; Edit The above returns SYSTEM if MySQL is set to use the system’s timezone, which is less than helpful. Since you’re using PHP, if the answer from MySQL is SYSTEM, you … Read more

Difference between timestamps with/without time zone in PostgreSQL

The differences are covered at the PostgreSQL documentation for date/time types. Yes, the treatment of TIME or TIMESTAMP differs between one WITH TIME ZONE or WITHOUT TIME ZONE. It doesn’t affect how the values are stored; it affects how they are interpreted. The effects of time zones on these data types is covered specifically in … Read more