I found a solution to transform a date like: Thu Sep 04 2014 00:00:00 GMT+0200 (Romance Daylight Time) to a format french 04/09/2014
How can i achieve this?
I found a solution to transform a date like: Thu Sep 04 2014 00:00:00 GMT+0200 (Romance Daylight Time) to a format french 04/09/2014
How can i achieve this?
You can do that by using the Date object and its functions:
function zerofy(number){
if(number < 10)
number = "0" + number;
return number;
}
var date = new Date("Thu Sep 04 2014 00:00:00 GMT+0200 (Romance Daylight Time)");
var day = zerofy(date.getDate());
var month = zerofy(date.getMonth());
var year = date.getFullYear();
var result = day + "/" + month + "/" + year
console.log(result);
I would recommend going over this document from MDN for these kind of problems.
Perhaps a basic one-liner would help?
function formatDate(date){
return [('0'+date.getDate()).slice(-2),('0'+date.getMonth()).slice(-2),date.getFullYear()].join('/');
}