SlideShare a Scribd company logo
MOMENT.JS
OVERVIEW
_by Oleksii Prohonnyi
IN A NUTSHELL
IN A NUTSHELL
 Parse, validate, manipulate, and display dates in JavaScript.
 Version: 2.13.0
 Download: http://momentjs.com/downloads/moment.js
 See more: http://momentjs.com/docs/
INSTALLATION
INSTALLATION
 bower install moment --save # bower
 npm install moment --save # npm
 Install-Package Moment.js # NuGet
 spm install moment --save # spm
 meteor add momentjs:moment # meteor
 See more: http://momentjs.com/docs/
WHERE TO USE
WHERE TO USE
 Moment was designed to work both in the browser and in Node.js.
 All code should work in both of these environments, and all unit tests are run in
both of these environments.
 Currently the following browsers are used for the ci system:
 Chrome on Windows XP,
 IE 8, 9, and 10 on Windows 7,
 IE 11 on Windows 10,
 latest Firefox on Linux,
 and latest Safari on OSX 10.8 and 10.11.
 See more: http://momentjs.com/docs/#/use-it/
PARSING
PARSING: General
 Instead of modifying the native Date.prototype, Moment.js creates a
wrapper for the Date object. To get this wrapper object, simply call
moment() with one of the supported input types.
 The Moment prototype is exposed through moment.fn. If you want
to add your own functions, that is where you would put them.
 See more: http://momentjs.com/docs/#/parsing/
PARSING: Input types (1)
 ISO 8601 format String:
moment("1995-12-25")
 String + Format:
moment("12-25-1995", "MM-DD-YYYY")
 String + Formats:
moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"])
 Special Formats:
moment("2010-01-01T05:06:07", moment.ISO_8601)
PARSING: Input types (2)
 Object:
moment({hour:15, minute:10})
 Unix Timestamp:
moment(1318781876406) #milliseconds
moment.unix(1318781876) #seconds
 Date:
moment(new Date(2011, 9, 16))
 Array:
moment([2010, 6, 10])
GET/SET
GET/SET
 Moment.js uses overloaded getters and setters. You may be familiar
with this pattern from its use in jQuery.
 Calling these methods without parameters acts as a getter, and
calling them with a parameter acts as a setter
moment().milliseconds(1464949616694)
moment().milliseconds()
 See more: http://momentjs.com/docs/#/get-set/
MANIPULATION
MANIPULATION: General
 Once you have a Moment, you may want to manipulate it in some way.
 Moment.js uses the fluent interface pattern, also known as method chaining.
moment().add(7, 'days')
.subtract(1, 'months')
.year(2009)
.hours(0)
.minutes(0)
.seconds(0);
 See more: http://momentjs.com/docs/#/manipulating/
MANIPULATION: Operations
 Add
 Substract
 Start of time
 End of time
 Local
 UTC
 UTC Offset
MANIPULATION: Example
var d = moment([2010, 0, 31]); // Jan 31, 2010
d.add(1, 'months'); // Feb 28, 2010
d.startOf('year'); // Jan 1, 2010 12:00
d.utcOffset(); // -240
DISPLAY
DISPLAY: Formatting
 Format
 Time from now
 Time from X
 Time to now
 Time to X
 Calendar Time
 Difference
 Unix Timestamp (milliseconds)
 Unix Timestamp (seconds)
 Days in Month
 As Javascript Date
 As Array
 As JSON
 As ISO 8601 String
 As Object
 As String
 See more: http://momentjs.com/docs/#/displaying/
DISPLAY: Example
var d = moment([2007, 01, 29]);
d.fromNow(); // “9 years ago"
d.from([2007, 01, 30]); // "a day ago"
moment([2007, 0, 29]).toNow(); // in 9 years
I18N
I18N: General
 Moment.js has robust support for internationalization.
 You can load multiple locales and easily switch between them.
 In addition to assigning a global locale, you can assign a locale to a specific
moment.
moment.locale('fr');
moment(1316116057189).fromNow() // "il y a une heure"
moment.locale('en');
moment(1316116057189).fromNow() // "an hour ago"
 See more: http://momentjs.com/docs/#/i18n/
I18N: Locale definition
 By default, Moment.js comes with English locale strings. If you need other locales, you can load
them into Moment.js for later use.
 More details on each of the parts of the locale bundle can be found in the customization section.
moment.locale('fr', {
months :
"janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_no
vembre_décembre".split("_"),
weekdaysMin : "Di_Lu_Ma_Me_Je_Ve_Sa".split("_"),
meridiemParse: /PD|MD/,
isPM: function (input) {
return input.charAt(0) === 'M';
}
});
FEW MORE THINGS
UTC
 By default, moment parses and displays in local time.
 If you want to parse or display a moment in UTC, you can use
moment.utc() instead of moment().
moment.utc([2011, 0, 1, 8])
moment([2011, 0, 1, 8])
 See more: http://momentjs.com/docs/#/parsing/utc/
CREATION DATA
 After a moment object is created, all of the inputs can be accessed with
creationData() method:
moment("13-01-02", "YY-MM-DD", true).creationData() === {
input: "13-01-02",
format: "YY-MM-DD",
locale: Locale obj,
isUTC: false,
strict: true
}
 See more: http://momentjs.com/docs/#/parsing/creation-data/
QUERIES
 Is Before
 Is Same
 Is After
 Is Same or Before
 Is Same or After
 Is Between
 Is Daylight Saving Time
 Is DST Shifted
 Is Leap Year
 Is a Moment
 Is a Date
 See more: http://momentjs.com/docs/#/query/
CUSTOMIZATION
 Moment.js is very easy to customize. In general, you
should create a locale setting with your customizations.
moment.locale('en-my-settings', {
// customizations.
});
 See more: http://momentjs.com/docs/#/customization/
PLUGINS
 Strftime
 ISO Calendar
 Date Ranges
 Twix
 Twitter
 Jalaali Calendar
 MSDate
 Fiscal Quarters
 Precise Range
 Recur
 Parse Date Format
 Java DateFormat Parser
 Hijri Calendar
 Round
 Transform
 Taiwan Calendar
 See more: http://momentjs.com/docs/#/plugins/
THANK YOU FOR
ATTENTION
Oleksii Prohonnyi
facebook.com/oprohonnyi
linkedin.com/in/oprohonnyi

More Related Content

PPTX
Mobile application development ppt
PDF
Native mobile application development with Flutter (Dart)
KEY
Introduction to Google App Engine
PDF
What is flutter and why should i care?
PDF
ExpressJS-Introduction.pdf
PDF
aws-overview (1).pdf
PPTX
Development of Mobile Application -PPT
PDF
Mobile application development ppt
Native mobile application development with Flutter (Dart)
Introduction to Google App Engine
What is flutter and why should i care?
ExpressJS-Introduction.pdf
aws-overview (1).pdf
Development of Mobile Application -PPT

What's hot (20)

PDF
Mobile development with Flutter
 
PPTX
Google Solution Challenge 2023
PDF
[Open southcode] ios testing with appium
PDF
Carbon Finance Risks and Opportunities
 
PPTX
Android with kotlin course
PPTX
CHATTING APPLICATION.pptx
PDF
Dissertation Proposal Ppt
PPT
Android PPT
PPTX
flutter intro.pptx
PPTX
Intern presentation based on Flutter Lawyer App.
PPTX
androidstudio.pptx
PPT
Node js
PPT
Mobile application development
PPTX
Android development
PPTX
Flutter Festivals GDSC ASEB | Introduction to Dart
PPTX
android architecture
PPT
Mobile Application Development MAD J2ME UNIT 2
PPTX
Mobile operating system
ZIP
Android Application Development
PDF
Flutter beyond hello world
Mobile development with Flutter
 
Google Solution Challenge 2023
[Open southcode] ios testing with appium
Carbon Finance Risks and Opportunities
 
Android with kotlin course
CHATTING APPLICATION.pptx
Dissertation Proposal Ppt
Android PPT
flutter intro.pptx
Intern presentation based on Flutter Lawyer App.
androidstudio.pptx
Node js
Mobile application development
Android development
Flutter Festivals GDSC ASEB | Introduction to Dart
android architecture
Mobile Application Development MAD J2ME UNIT 2
Mobile operating system
Android Application Development
Flutter beyond hello world
Ad

Viewers also liked (20)

PPTX
Cycle.js overview
PPTX
Asm.js introduction
PPTX
Utility libraries to make your life easier
PPTX
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
DOCX
RESUME2014
PPTX
Exploradores.caroes
PPTX
Dive into Angular, part 5: Experience
PPTX
Front-end rich JavaScript application creation (Backbone.js)
PPTX
КаĐș ŃĐŸĐ·ĐŽĐ°Ń‚ŃŒ саĐčт за 2 часа? (Wordpress)
PPTX
Conference DotJS 2015 Paris review
PPTX
Dive into Angular, part 3: Performance
PPT
Đ Đ°Đ·Ń€Đ°Đ±ĐŸŃ‚Đșа ĐČДб-саĐčта. ХаĐčт. Đ—Đ°Ń‡Đ”ĐŒ ĐŸĐœ?
PPTX
Chorme devtools
PPTX
OpenLayer's basics
PPTX
Dive into Angular, part 1: Introduction
PPTX
Bower introduction
PDF
Chrome DevTools Awesome 10 Features +1
PPTX
Google Chrome DevTools features overview
PPTX
Introduction to D3.js
PPTX
JavaScript Presentation Frameworks and Libraries
Cycle.js overview
Asm.js introduction
Utility libraries to make your life easier
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
RESUME2014
Exploradores.caroes
Dive into Angular, part 5: Experience
Front-end rich JavaScript application creation (Backbone.js)
КаĐș ŃĐŸĐ·ĐŽĐ°Ń‚ŃŒ саĐčт за 2 часа? (Wordpress)
Conference DotJS 2015 Paris review
Dive into Angular, part 3: Performance
Đ Đ°Đ·Ń€Đ°Đ±ĐŸŃ‚Đșа ĐČДб-саĐčта. ХаĐčт. Đ—Đ°Ń‡Đ”ĐŒ ĐŸĐœ?
Chorme devtools
OpenLayer's basics
Dive into Angular, part 1: Introduction
Bower introduction
Chrome DevTools Awesome 10 Features +1
Google Chrome DevTools features overview
Introduction to D3.js
JavaScript Presentation Frameworks and Libraries
Ad

Similar to Moment.js overview (16)

PDF
Demystifying Temporal
 
PPTX
MomentJS at SeattleJS
PDF
Demystifying Temporal: A Deep Dive into JavaScript New Temporal API
 
PPTX
Data and time
PPTX
Date and Time MomentJS Edition
PPTX
That Conference Date and Time
PPTX
Date object.pptx date and object v
 
PPTX
XDate - a modern java-script date library
PDF
Java 8 date & time api
PDF
Intro to JavaScript - Week 4: Object and Array
PPTX
Date and Time Odds Ends Oddities
PDF
How to work with dates and times in swift 3
PPTX
2.java script dom
PDF
JavaScript for impatient programmers.pdf
PDF
Java 8 date & time
PPTX
Java 8 Date and Time API
Demystifying Temporal
 
MomentJS at SeattleJS
Demystifying Temporal: A Deep Dive into JavaScript New Temporal API
 
Data and time
Date and Time MomentJS Edition
That Conference Date and Time
Date object.pptx date and object v
 
XDate - a modern java-script date library
Java 8 date & time api
Intro to JavaScript - Week 4: Object and Array
Date and Time Odds Ends Oddities
How to work with dates and times in swift 3
2.java script dom
JavaScript for impatient programmers.pdf
Java 8 date & time
Java 8 Date and Time API

More from Oleksii Prohonnyi (11)

PPTX
Dive into Angular, part 4: Angular 2.0
PPTX
Dive into Angular, part 2: Architecture
PPTX
Code review process with JetBrains UpSource
PPTX
BEM methodology overview
PPTX
Front-end development introduction (JavaScript). Part 2
PPTX
Front-end development introduction (HTML, CSS). Part 1
PPTX
Test-driven development & Behavior-driven development basics
PPTX
JavaScript Coding Guidelines
PPTX
Database Optimization (MySQL)
PPTX
PHPCS (PHP Code Sniffer)
PPTX
Usability of UI Design (motivation, heuristics, tools)
Dive into Angular, part 4: Angular 2.0
Dive into Angular, part 2: Architecture
Code review process with JetBrains UpSource
BEM methodology overview
Front-end development introduction (JavaScript). Part 2
Front-end development introduction (HTML, CSS). Part 1
Test-driven development & Behavior-driven development basics
JavaScript Coding Guidelines
Database Optimization (MySQL)
PHPCS (PHP Code Sniffer)
Usability of UI Design (motivation, heuristics, tools)

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
assetexplorer- product-overview - presentation
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Digital Strategies for Manufacturing Companies
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
top salesforce developer skills in 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Computer Software and OS of computer science of grade 11.pptx
Reimagine Home Health with the Power of Agentic AI​
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
wealthsignaloriginal-com-DS-text-... (1).pdf
assetexplorer- product-overview - presentation
Odoo POS Development Services by CandidRoot Solutions
Softaken Excel to vCard Converter Software.pdf
Nekopoi APK 2025 free lastest update
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Operating system designcfffgfgggggggvggggggggg
Digital Strategies for Manufacturing Companies
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Internet Downloader Manager (IDM) Crack 6.42 Build 41
top salesforce developer skills in 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

Moment.js overview

  • 3. IN A NUTSHELL  Parse, validate, manipulate, and display dates in JavaScript.  Version: 2.13.0  Download: http://momentjs.com/downloads/moment.js  See more: http://momentjs.com/docs/
  • 5. INSTALLATION  bower install moment --save # bower  npm install moment --save # npm  Install-Package Moment.js # NuGet  spm install moment --save # spm  meteor add momentjs:moment # meteor  See more: http://momentjs.com/docs/
  • 7. WHERE TO USE  Moment was designed to work both in the browser and in Node.js.  All code should work in both of these environments, and all unit tests are run in both of these environments.  Currently the following browsers are used for the ci system:  Chrome on Windows XP,  IE 8, 9, and 10 on Windows 7,  IE 11 on Windows 10,  latest Firefox on Linux,  and latest Safari on OSX 10.8 and 10.11.  See more: http://momentjs.com/docs/#/use-it/
  • 9. PARSING: General  Instead of modifying the native Date.prototype, Moment.js creates a wrapper for the Date object. To get this wrapper object, simply call moment() with one of the supported input types.  The Moment prototype is exposed through moment.fn. If you want to add your own functions, that is where you would put them.  See more: http://momentjs.com/docs/#/parsing/
  • 10. PARSING: Input types (1)  ISO 8601 format String: moment("1995-12-25")  String + Format: moment("12-25-1995", "MM-DD-YYYY")  String + Formats: moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"])  Special Formats: moment("2010-01-01T05:06:07", moment.ISO_8601)
  • 11. PARSING: Input types (2)  Object: moment({hour:15, minute:10})  Unix Timestamp: moment(1318781876406) #milliseconds moment.unix(1318781876) #seconds  Date: moment(new Date(2011, 9, 16))  Array: moment([2010, 6, 10])
  • 13. GET/SET  Moment.js uses overloaded getters and setters. You may be familiar with this pattern from its use in jQuery.  Calling these methods without parameters acts as a getter, and calling them with a parameter acts as a setter moment().milliseconds(1464949616694) moment().milliseconds()  See more: http://momentjs.com/docs/#/get-set/
  • 15. MANIPULATION: General  Once you have a Moment, you may want to manipulate it in some way.  Moment.js uses the fluent interface pattern, also known as method chaining. moment().add(7, 'days') .subtract(1, 'months') .year(2009) .hours(0) .minutes(0) .seconds(0);  See more: http://momentjs.com/docs/#/manipulating/
  • 16. MANIPULATION: Operations  Add  Substract  Start of time  End of time  Local  UTC  UTC Offset
  • 17. MANIPULATION: Example var d = moment([2010, 0, 31]); // Jan 31, 2010 d.add(1, 'months'); // Feb 28, 2010 d.startOf('year'); // Jan 1, 2010 12:00 d.utcOffset(); // -240
  • 19. DISPLAY: Formatting  Format  Time from now  Time from X  Time to now  Time to X  Calendar Time  Difference  Unix Timestamp (milliseconds)  Unix Timestamp (seconds)  Days in Month  As Javascript Date  As Array  As JSON  As ISO 8601 String  As Object  As String  See more: http://momentjs.com/docs/#/displaying/
  • 20. DISPLAY: Example var d = moment([2007, 01, 29]); d.fromNow(); // “9 years ago" d.from([2007, 01, 30]); // "a day ago" moment([2007, 0, 29]).toNow(); // in 9 years
  • 21. I18N
  • 22. I18N: General  Moment.js has robust support for internationalization.  You can load multiple locales and easily switch between them.  In addition to assigning a global locale, you can assign a locale to a specific moment. moment.locale('fr'); moment(1316116057189).fromNow() // "il y a une heure" moment.locale('en'); moment(1316116057189).fromNow() // "an hour ago"  See more: http://momentjs.com/docs/#/i18n/
  • 23. I18N: Locale definition  By default, Moment.js comes with English locale strings. If you need other locales, you can load them into Moment.js for later use.  More details on each of the parts of the locale bundle can be found in the customization section. moment.locale('fr', { months : "janvier_fĂ©vrier_mars_avril_mai_juin_juillet_aoĂ»t_septembre_octobre_no vembre_dĂ©cembre".split("_"), weekdaysMin : "Di_Lu_Ma_Me_Je_Ve_Sa".split("_"), meridiemParse: /PD|MD/, isPM: function (input) { return input.charAt(0) === 'M'; } });
  • 25. UTC  By default, moment parses and displays in local time.  If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment(). moment.utc([2011, 0, 1, 8]) moment([2011, 0, 1, 8])  See more: http://momentjs.com/docs/#/parsing/utc/
  • 26. CREATION DATA  After a moment object is created, all of the inputs can be accessed with creationData() method: moment("13-01-02", "YY-MM-DD", true).creationData() === { input: "13-01-02", format: "YY-MM-DD", locale: Locale obj, isUTC: false, strict: true }  See more: http://momentjs.com/docs/#/parsing/creation-data/
  • 27. QUERIES  Is Before  Is Same  Is After  Is Same or Before  Is Same or After  Is Between  Is Daylight Saving Time  Is DST Shifted  Is Leap Year  Is a Moment  Is a Date  See more: http://momentjs.com/docs/#/query/
  • 28. CUSTOMIZATION  Moment.js is very easy to customize. In general, you should create a locale setting with your customizations. moment.locale('en-my-settings', { // customizations. });  See more: http://momentjs.com/docs/#/customization/
  • 29. PLUGINS  Strftime  ISO Calendar  Date Ranges  Twix  Twitter  Jalaali Calendar  MSDate  Fiscal Quarters  Precise Range  Recur  Parse Date Format  Java DateFormat Parser  Hijri Calendar  Round  Transform  Taiwan Calendar  See more: http://momentjs.com/docs/#/plugins/