- 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 - Time to X
This method will help to display moment as per in relation with another moment instead of current one.
Syntax
moment().to(Moment|String|Number|Date|Array); moment().to(Moment|String|Number|Date|Array, Boolean);
Example
var a = moment([1995, 3, 15]); var b = moment([1998, 10, 01]); var c = a.to(b);
OR
Example
var a = moment([1995, 3, 15]).to(moment([1998, 10, 01]));
Output
Example 2
var a = moment([1995, 3, 15]).to(new Date());
Output
Example 3
var a = moment([2018, 10, 11]).to(moment[2015, 10, 11], true);
Output
If you want to remove the prefix in or ago in the display, use true.
momentjs_formatting_date_and_time.htm
Advertisements