4

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?

1
  • its not possible for me. bcse , its can be any country's time zone. Commented Mar 9, 2016 at 11:13

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Following your question, you can use:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.