hoangh
0
Q:

javascript moment

moment(testDate).format('MM/DD/YYYY');
7
npm install moment --save   # npm
yarn add moment             # Yarn
moment.locale();         // en
moment().format('LT');   // 8:49 AM
moment().format('LTS');  // 8:49:26 AM
moment().format('L');    // 10/13/2020
moment().format('l');    // 10/13/2020
moment().format('LL');   // October 13, 2020
moment().format('ll');   // Oct 13, 2020
moment().format('LLL');  // October 13, 2020 8:49 AM
moment().format('lll');  // Oct 13, 2020 8:49 AM
moment().format('LLLL'); // Tuesday, October 13, 2020 8:49 AM
moment().format('llll'); // Tue, Oct 13, 2020 8:49 AM
5
moment().format();                                // "2019-08-12T17:52:17-05:00" (ISO 8601, no fractional seconds)
moment().format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Monday, August 12th 2019, 5:52:00 pm"
moment().format("ddd, hA");                       // "Mon, 5PM"
9
moment().format('MMMM Do YYYY, h:mm:ss a'); // May 22nd 2020, 6:00:23 pm
moment().format('dddd');                    // Friday
moment().format("MMM Do YY");               // May 22nd 20
moment().format('YYYY [escaped] YYYY');     // 2020 escaped 2020
moment().format();                          // 2020-05-22T18:00:23+05:30
4
var time = "15:30:00";
var formatted = moment(time, "HH:mm:ss").format("LT");
console.log(formatted); 
//it will return 3:30 PM
3
moment.locale();         // en
moment().format('LT');   // 8:41 PM
moment().format('LTS');  // 8:41:43 PM
moment().format('L');    // 04/11/2020
moment().format('l');    // 4/11/2020
moment().format('LL');   // April 11, 2020
moment().format('ll');   // Apr 11, 2020
moment().format('LLL');  // April 11, 2020 8:41 PM
moment().format('lll');  // Apr 11, 2020 8:41 PM
moment().format('LLLL'); // Saturday, April 11, 2020 8:41 PM
moment().format('llll'); // Sat, Apr 11, 2020 8:41 PM
                         // undefined
2
moment("20111031", "YYYYMMDD").fromNow(); // há 9 anos
moment("20120620", "YYYYMMDD").fromNow(); // há 8 anos
moment().startOf('day').fromNow();        // há 13 horas
moment().endOf('day').fromNow();          // em 11 horas
moment().startOf('hour').fromNow();       // há 10 minutos
2
moment().getDate();
1
m = moment('2013-03-01', 'YYYY-MM-DD')
0
npm install moment --save   # npm
yarn add moment             # Yarn
Install-Package Moment.js   # NuGet
spm install moment --save   # spm
meteor add momentjs:moment  # meteor
bower install moment --save # bower (deprecated)
2

New to Communities?

Join the community