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

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

Ignoring time zones altogether in Rails and PostgreSQL

Postgres has two different timestamp data types: timestamp with time zone, short name: timestamptz timestamp without time zone, short name: timestamp timestamptz is the preferred type in the date/time family, literally. It has typispreferred set in pg_type, which can be relevant: Generating time series between two dates in PostgreSQL Internal storage and epoch Internally, timestamps … Read more

How to initialize a JavaScript Date to a particular time zone

Background JavaScript’s Date object tracks time in UTC internally, but typically accepts input and produces output in the local time of the computer it’s running on. It has very few facilities for working with time in other time zones. The internal representation of a Date object is a single number, representing the number of milliseconds … Read more