MomentJS - UTC


Advertisements

For moment.utc, the date will be parsed and displayed in local time. By default, date will be shown in local time. In case you need to parse it in UTC, you can make use of this method.

Syntax

moment.utc();

moment.utc can take params as number, string, moment, date etc. This method can be used when the date displayed has to be in UTC format.

Example

var date1 = moment.utc();

Output

UTC

Any moment created with moment.utc() will be in UTC mode, and any moment created with moment() will be not.

The following example shows the hours fetched from local and utc moment −

Example

var a = moment().hours();
var b = moment.utc().hours();

Output

Hours Fetched

Observe an additional example showing the display of date in utc and local mode −

Example

var a = moment().format();
var b = moment.utc().format();

Output

Display of Date
momentjs_parsing_date_and_time.htm
Advertisements