How to convert a UTC datetime to a local datetime using only standard library?

In Python 3.3+: from datetime import datetime, timezone def utc_to_local(utc_dt): return utc_dt.replace(tzinfo=timezone.utc).astimezone(tz=None) In Python 2/3: import calendar from datetime import datetime, timedelta def utc_to_local(utc_dt): # get integer timestamp to avoid precision lost timestamp = calendar.timegm(utc_dt.timetuple()) local_dt = datetime.fromtimestamp(timestamp) assert utc_dt.resolution >= timedelta(microseconds=1) return local_dt.replace(microsecond=utc_dt.microsecond) Using pytz (both Python 2/3): import pytz local_tz = pytz.timezone(‘Europe/Moscow’) # … Read more

List of Timezone IDs for use with FindTimeZoneById() in C#?

Here’s a full listing of a program and its results. The code: using System; namespace TimeZoneIds { class Program { static void Main(string[] args) { foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones()) { // For a Console App Console.WriteLine(z.Id + “,” + z.BaseUtcOffset + “,” + z.StandardName + “,” + z.DisplayName + “,” + z.DaylightName); // For … Read more

“date(): It is not safe to rely on the system’s timezone settings…”

You probably need to put the timezone in a configuration line in your php.ini file. You should have a block like this in your php.ini file: [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = America/New_York If not, add it (replacing the timezone by yours). After configuring, make sure … Read more

How to get a time zone from a location using latitude and longitude coordinates?

Time Zone Location Web Services Google Maps Time Zone API Bing Maps Time Zone API Azure Maps Time Zone API GeoNames Time Zone API TimeZoneDB API AskGeo – commercial (but arguably more accurate than GeoNames) GeoGarage Time Zone API – commercial, focusing on Nautical time zones. Raw Time Zone Boundary Data Timezone Boundary Builder – … Read more

How do I set the time zone of MySQL?

I thought this might be useful: There are three places where the timezone might be set in MySQL: In the file “my.cnf” in the [mysqld] section default-time-zone=”+00:00″ @@global.time_zone variable To see what value they are set to: SELECT @@global.time_zone; To set a value for it use either one: SET GLOBAL time_zone=”+8:00″; SET GLOBAL time_zone=”Europe/Helsinki”; SET … Read more

Can’t subtract offset-naive and offset-aware datetimes

have you tried to remove the timezone awareness? from http://pytz.sourceforge.net/ naive = dt.replace(tzinfo=None) may have to add time zone conversion as well. edit: Please be aware the age of this answer. An answer involving ADDing the timezone info instead of removing it in python 3 is below. https://stackoverflow.com/a/25662061/93380

How do I get a value of datetime.today() in Python that is “timezone aware”?

In the standard library, there is no cross-platform way to create aware timezones without creating your own timezone class. (Edit: Python 3.9 introduces zoneinfo in the standard library which does provide this functionality.) On Windows, there’s win32timezone.utcnow(), but that’s part of pywin32. I would rather suggest to use the pytz library, which has a constantly … Read more

Convert date to another timezone in JavaScript

Here is the one-liner: function convertTZ(date, tzString) { return new Date((typeof date === “string” ? new Date(date) : date).toLocaleString(“en-US”, {timeZone: tzString})); } // usage: Asia/Jakarta is GMT+7 convertTZ(“2012/04/20 10:10:30 +0000”, “Asia/Jakarta”) // Tue Apr 20 2012 17:10:30 GMT+0700 (Western Indonesia Time) // Resulting value is regular Date() object const convertedDate = convertTZ(“2012/04/20 10:10:30 +0000”, “Asia/Jakarta”) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)