Question

When creating a moment date object using the following settings:

var date = moment({
    year:   2014,
    month:  2,
    day:    17,
    hour:   9,
    minute: 60
});
date.isValid(); // false

Mon Mar 17 2014 10:00:00 GMT+0100 (Romance Standard Time)

The output is correct but when I try to validate this date, it is incorrect. I think it's because the mintues are greater than 60. Normally this would not be a problem but i'm using Twix to create ranges and due to this problem i'm getting invalid dates. Is there any way to fix this issue?

Était-ce utile?

La solution

You may use the native Date constructor to deal with overflows for you :

var date = moment(new Date(2014,2,17,9,60));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top