DEV Community

karthikeyan
karthikeyan

Posted on • Edited on

3

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more