Javascript wrong date format
I format a date object from a string in javascript but but when i print
the formatted date i found it increased two years !!
alert("Date1-Without-conversion:" + document.getElementById(arr[0]).value);
alert("Date2-Without-conversion:" + document.getElementById(arr[1]).value);
it prints:
30/9/2018
04/10/2018
date1Str=document.getElementById(arr[0]).value;
date2Str=document.getElementById(arr[1]).value;
date1 = new Date(date1Str);
date2 = new Date(date2Str);
alert("Date1-After-conversion:" + date1);
alert("Dat2-After-conversion:" + date2);
prints:
Tue Jun 09 2020 00:00:00 GMT+0200(Egypt Standard Time)
Tue Apr 10 2018 00:00:00 GMT+0200(Egypt Standard Time)
i used this function to format the date as DD/MM/YYYY
function formatDate(inputFormat) {
var d = new Date(inputFormat);
return [d.getDate(), d.getMonth()+1, d.getFullYear()].join('/');
}
but it know prints:
9/5/2020
10/7/2020
How come ??
No comments:
Post a Comment