I am currently using moment.js (moment-with-locales.js - v.2.14.1) in my project. My goal is to extract only the date from a datetime string and remove the time. However, when I use the .format()
method of moment.js, I receive an incorrect date.
The datetime string that I want to format is:
from ' 08.10.2016 11:00 ' to ' 08.10.2016 '
Here is the code snippet I used in my Angular project:
var date = moment('08.10.2016 11:00').format('DD.MM.YYYY')
console.log(date)
When I run this code, the output I get is:
10.08.2016
instead of 08.10.2016
Interestingly, if I try to retrieve the timestamp (in milliseconds) of my datetime string, it works perfectly fine. For example:
var dateStart = moment('08.10.2016 19:00', 'DD.MM.YYYY HH:mm').valueOf()
console.log(dateStart)
This will return:
1475946000000 -> Sat Oct 08 2016 19:00:00 GMT+0200
How can I ensure that I get the correct Date?