- MomentJS Tutorial
- MomentJS - Home
- MomentJS - Overview
- MomentJS - Environment Setup
- MomentJS - Introduction
- MomentJS - Parsing Date And Time
- MomentJS - Date Validation
- MomentJS - Getter/Setter
- Manipulate Date And Time
- Formatting Date And Time
- MomentJS - Date Queries
- MomentJS - Internationalization
- MomentJS - Customization
- MomentJS - Durations
- MomentJS - Utilities
- MomentJS - Plugins
- MomentJS - Examples
- MomentJS Useful Resources
- MomentJS - Quick Guide
- MomentJS - Useful Resources
- MomentJS - Discussion
MomentJS - UTC
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
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
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
momentjs_parsing_date_and_time.htm
Advertisements