Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment.js: how to initialize from DD/MM/YYYY format

Tags:

momentjs

I want to initilize moment from DD/MM/YYYY format ex:

var xmas = moment('25/12/2016'); //does not work


var xmas = moment('2016-12-25');// works

Any idea ?

like image 716
yarek Avatar asked Sep 25 '16 13:09

yarek


People also ask

How do you get only the date from dd mm yyyy?

const dateFormat = 'DD/MM/YYYY'; setValue('startDate', moment(booking. startDate, dateFormat));

Is MomentJS obsolete?

We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done. Letting things go instead of creating a new major version is the right choice. Moment's usage is so widespread that it's impossible to deprecate the current version over time.

How do you find a moment from a date?

Date format conversion with Moment is simple, as shown in the following example. moment(). format('YYYY-MM-DD'); Calling moment() gives us the current date and time, while format() converts it to the specified format.


1 Answers

you just had to scroll the docs down a bit to the String + Format section

var xmas = moment('25/12/2016', 'DD/MM/YYYY')
like image 73
jamey graham Avatar answered Oct 21 '22 04:10

jamey graham