Format the existing date variable with moment. Js
I have a date variable (coming from an external source):
var date = '28/04/2017';
var time = '19:28';
Is it possible to format these variables with moment .js (or without?) To display formats?
Example: 04.28 19:28, 2017.04.28 19:28 or even today at 19:28 (with moment (). Calendar ();)
I tried
moment(date+' '+time).format('MM.DD.YYYY');
... but I get an Invalid Date error.
+3
source to share
4 answers
You are using the method moment(String)
, but you are not passing the Supported format that it expects to parse.
You should use moment(String, String)
where the first line is the date input string and the second is the input string format.
Try the following:
moment(date+' '+time,'DD/MM/YYYY HH:mm').format('MM.DD.YYYY');
+8
source to share