sac Dahal
sac Dahal

Reputation: 1241

using moment.Js to create current date and time by giving user defined values for time

Suppose I gave a value as 4:30 I then split them into something like this ['4' , '30']. I want to use moment to format it into something like this moment("2010-10-20 4:30", "YYYY-MM-DD HH:mm"); // parsed as 4:30 localtime any clues..?

here the date will be todays date.

Upvotes: 0

Views: 163

Answers (1)

Andrei Karpuszonak
Andrei Karpuszonak

Reputation: 9034

You can achieve this by

var moment = require('moment')
moment("2010-10-20 04:30").format("YYYY-MM-DD HH:mm"); // will produce '2010-10-20 04:30'

More format examples:

moment().format('MMMM Do YYYY, h:mm:ss a'); // November 9th 2016, 11:47:05 am
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Nov 9th 16
moment().format('YYYY [escaped] YYYY');     // 2016 escaped 2016
moment().format();                          // 2016-11-09T11:47:05+01:00

Upvotes: 1

Related Questions