I need to convert a Java Date object to a string that is the same format as JavaScript Dates when they are converted to a string. On our server we have JavaScript dates that
Typically if a given date is valid then the date object created should return back the same date, month and year value. Below logic worked for most of the cases that I coded.
Example: 29-Feb-2018 does not exist, but when javascript accepts this input as Date("2018-02-29") it creates a date value of 1-Mar-2018.
Javascript Function:
function dateCheck(dd,mm,yyyy)
{
var tempDt = new Date(parseInt(yyyy), parseInt(mm)-1, parseInt(dd), 0, 0, 0, 0);
if(tempDt.getDate()!=parseInt(dd) ||
tempDt.getFullYear()!=parseInt(yyyy) ||
tempDt.getMonth() + 1 !=parseInt(mm))
return false;
else
return true;
}