DEV Community

Karthikeyan
Karthikeyan

Posted on • Edited on

REACT JS timezone using moment-timezone

get timezone according to ip address or location using moment timezone library

function App() {

var moment = require('moment-timezone');
var timeZone = moment.tz.guess();
console.log(timeZone);
var time = new Date();
console.log(time);
var timeZoneOffset = time.getTimezoneOffset();
console.log(timeZoneOffset);
var abbr = moment.tz.zone(timeZone).abbr(timeZoneOffset);
console.log(abbr);
return (



);
}

export default App;

output :

Asia/Calcutta
Mon Jun 28 2021 11:39:16 GMT+0530 (India Standard Time)
-330
IST
Enter fullscreen mode Exit fullscreen mode

Top comments (0)