Abdul Manaf
Abdul Manaf

Reputation: 4993

Get time from time zone using node js

i need to print actual time from timezone using node js. iam using moment-timezone to find out the time from time zones.

This is my code

var moment = require('moment-timezone');

console.log(moment().tz("UTC+05:30").format());
console.log(moment().tz("UTC+05").format());
console.log(moment().tz("UTC−04:30").format());
console.log(moment().tz("UTC+08").format());
console.log(moment().tz("UTC+06").format());

But i got result like this

Moment Timezone has no data for UTC+05:30. See http://momentjs.com/timezone/docs/#/data-loading/.
2016-03-09T16:31:10+05:30
Moment Timezone has no data for UTC+05. See http://momentjs.com/timezone/docs/#/data-loading/.
2016-03-09T16:31:10+05:30
Moment Timezone has no data for UTC−04:30. See http://momentjs.com/timezone/docs/#/data-loading/.
2016-03-09T16:31:10+05:30
Moment Timezone has no data for UTC+08. See http://momentjs.com/timezone/docs/#/data-loading/.
2016-03-09T16:31:10+05:30
Moment Timezone has no data for UTC+06. See http://momentjs.com/timezone/docs/#/data-loading/.
2016-03-09T16:31:10+05:30

How to solve this issue?

Upvotes: 4

Views: 2005

Answers (2)

pikzen
pikzen

Reputation: 1443

As indicated in the documentation, moment.tz([string]) expects [string] to be in the 'Country/City' format, and does NOT accept UTC+XX formats.

Use moment().utcOffset([string]) to apply UTC offsets before formatting.

Upvotes: 4

alexey
alexey

Reputation: 1411

Following your question, you can use:

moment().utcOffset(520).format() // for UTC+5:30

Upvotes: 0

Related Questions