3
Good Afternoon. How do I convert a date into Java, taking into account the date entered may be day-month-year or year-day-month. I have the following code:
data = toDate('2015-10-01');
function toDate(dateStr) {
dateStr = dateStr.replace('/', '-');
var parts = dateStr.split("-");
return new Date(parts[2], parts[1] - 1, parts[0]);
}
But the function does not solve the problem if I entered the date with formats 01-10-2015 or 01/10/2015.
What solutions do I have? Thank you.
I advise you to have only one type of input mask. Is there a specific reason for having two input masks?
– durtto
Will the year always have 4 characters? For example: 1998 instead of 98? In addition, in the question the format is "year-day-month", which means that the date of example there is "10 January 2015". That’s right?
– Gabe