Monday, January 13, 2020

Moment js examples

moment().format('MMMM Do YYYY, h:mm:ss a')January 13th 2020, 3:19:07 pm
moment().format('dddd')Monday
moment().format('MMM Do YY')Jan 13th 20
moment().format('YYYY [escaped] YYYY')2020 escaped 2020
moment().format()2020-01-13T15:19:07+06:00
moment(new Date()).format('MMMM Do YYYY, h:mm:ss a')January 13th 2020, 3:19:07 pm
moment(new Date(2012,12,3)) < moment(new Date(2012,12,1))false
moment(new Date(2012,12,3)) < moment(new Date(2012,12,4))true
moment('2014-02-17T08:30:00').format('MMMM Do YYYY, h:mm:ss a')February 17th 2014, 8:30:00 am

MomentResult
moment('20111031', 'YYYYMMDD').fromNow()8 years ago
moment('20120620', 'YYYYMMDD').fromNow()8 years ago
moment().startOf('day').fromNow()15 hours ago
moment().endOf('day').fromNow()in 9 hours
moment().startOf('hour').fromNow()19 minutes ago

MomentResult
moment().format('MMMM Do YYYY, h:mm:ss a')January 13th 2020, 3:19:07 pm
moment().add('days', 7).format('MMMM Do YYYY, h:mm:ss a')January 20th 2020, 3:19:07 pm
moment().add('days', 7).add('months', 1).format('MMMM Do YYYY, h:mm:ss a')February 20th 2020, 3:19:07 pm
moment().add({days:7,months:1}).format('MMMM Do YYYY, h:mm:ss a')February 20th 2020, 3:19:07 pm
moment().add('milliseconds', 1000000).format('MMMM Do YYYY, h:mm:ss a')January 13th 2020, 3:35:47 pm
moment().add('days', 360).format('MMMM Do YYYY, h:mm:ss a')January 7th 2021, 3:19:07 pm
moment(new Date(2012,12,3,6,0,0,0)) - moment(new Date(2012,12,3,5,0,0,0))3600000
(new Date(2012,12,3,6,0,0,0)) - (new Date(2012,12,3,5,0,0,0))3600000
new Date().getTimezoneOffset()-360
moment(new Date()).zone()-360
(new Date(2013,2,1,14,22,0,0)) - (new Date(2013,1,30,13,22,0,0))-82800000
moment('5/17/2013 1:45PM', 'DD/MM/YYYY hh:mm:ssa').format('MMMM Do YYYY, h:mm:ss a')May 5th 2014, 1:45:00 pm
(moment('2014-02-17T16:30:00')).format('MMMM Do YYYY, h:mm:ss a')February 17th 2014, 4:30:00 pm
(moment('2014-02-17T16:30:00z')).format('MMMM Do YYYY, h:mm:ss a')February 17th 2014, 10:30:00 pm
new Date('2014-02-17T16:30:00z')Mon Feb 17 2014 22:30:00 GMT+0600 (Bangladesh Standard Time)

https://codepen.io/bassfiddle/pen/lrLwy?__cf_chl_jschl_tk__=0943c67cf5ff73480726a5ac8e5763ebb56522ae-1578907142-0-AbBkBcHLw26HIyPKro4vU7EsZF5vhL3G8LVFxWAC2jT37WBmIFhcNIEgck9E8cAdeMLH1NQ47enPSkDkt450LHjXG1pPpY18RU1VY7yM-bKr97mqZCW8ZZ53Okv6V-yQ7MB_do_Y74h6f7VNCcPTTcKFkXrRZVAgDARL0BeYdl4oeS0pTZxGNiwwWTpNrcmFys5TKpyZzqse4t6LfZfW2Tgbn1KohgagcD687HA9pU2P89A42M3wongqOLd-UDwoHcZ-XVxuTPIeVwCtYNGdG2ZAR4Lhv0wbdw5K0T3I0cB2bUShXNoS-h-xevErZnZNO0dvH7Z8bcJIRykjtU2dsFy5I7mgeWj4i6ngs-CU6P4l