2

So from an input like the country: US and state: CA I'd need to get the timezone.

I saw this response here: Get timezone directly from Country and State Google API, but the problem is that Google API needs longitude and latitude, so I wonder if I first need to look for these values. Is there any option to get the timezone directly?

Thank you

Albert
  • 146
  • 2
  • 12

3 Answers3

0

Moment.js gives you some functionality to do this

I have installed it with npm install moment-timezone

Then you can get the TimeZone as follows here for California using Los_Angeles

var moment = require('moment-timezone');
moment().tz("America/Los_Angeles").format();

var a = moment.tz("2013-11-18 11:55", "America/Los_Angeles");
var b = moment.tz("2013-11-18 11:55", "America/Toronto");



console.log(a.format()); // 2013-11-18T11:55:00-08:00
console.log(b.format()); // 2013-11-18T11:55:00-05:00

console.log(a.utc().format()); // 2013-11-18T19:55:00Z
console.log(b.utc().format()); // 2013-11-18T16:55:00Z
Aalexander
  • 4,987
  • 3
  • 11
  • 34
  • 1
    That’s actually a good option, I’d just to convert country and state ISO2 codes to long version. LA - Los_Angeles. Thank you, I’ll try this out – Albert Jan 01 '21 at 12:35
0

check this https://momentjs.com/timezone/docs/

var timestamp = 1403454068850,
    date = new Date(timestamp);

moment.tz(timestamp, "America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
moment(timestamp).tz("America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
Veer R
  • 129
  • 1
  • 9
0

You can use this npm module countries-and-timezones

const ct = require('countries-and-timezones');
     
const timezone = ct.getCountryForTimezone('Asia/Tokyo');
console.log(timezone);
 
Aalexander
  • 4,987
  • 3
  • 11
  • 34
  • Interesting option thank you, I’m missing an easy way to find the state time zone though, anyways I’ll investigate more about this package – Albert Jan 01 '21 at 12:38