Convert date object in dd/mm/yyyy hh:mm:ss format
You can fully format the string as mentioned in other posts. But I think your better off using the locale functions in the date object?
var d = new Date("2017-03-16T17:46:53.677");
console.log( d.toLocaleString() );
edit :
ISO 8601 ( the format you are constructing with ) states the time zone is appended at the end with a [{+|-}hh][:mm]
at the end of the string.
so you could do this :
var tzOffset = "+07:00"
var d = new Date("2017-03-16T17:46:53.677"+ tzOffset);
console.log(d.toLocaleString());
var d = new Date("2017-03-16T17:46:53.677"); // assumes local time.
console.log(d.toLocaleString());
var d = new Date("2017-03-16T17:46:53.677Z"); // UTC time
console.log(d.toLocaleString());
edit :
Just so you know the locale
function displays the date and time in the manner of the users language and location. European date is dd/mm/yyyy
and US is mm/dd/yyyy
.
var d = new Date("2017-03-16T17:46:53.677");
console.log(d.toLocaleString("en-US"));
console.log(d.toLocaleString("en-GB"));
Here we go:
var today = new Date();
var day = today.getDate() + "";
var month = (today.getMonth() + 1) + "";
var year = today.getFullYear() + "";
var hour = today.getHours() + "";
var minutes = today.getMinutes() + "";
var seconds = today.getSeconds() + "";
day = checkZero(day);
month = checkZero(month);
year = checkZero(year);
hour = checkZero(hour);
minutes = checkZero(minutes);
seconds = checkZero(seconds);
console.log(day + "/" + month + "/" + year + " " + hour + ":" + minutes + ":" + seconds);
function checkZero(data){
if(data.length == 1){
data = "0" + data;
}
return data;
}