Question

I want to display the date timestamp retrieved from a MySQL database in a HTML table dynamically. I have an array of dates. I am getting date in the following format:

Mar 10, 2014 6:40:45 AM

How can I get the date as it is and represent it in my HTML table using JavaScript?

Était-ce utile?

La solution

Assuming that Mar 10, 2014 6:40:45 AM is your input date format, This code will help:

var myDate = new Date('Mar 10, 2014 6:40:45 AM');
var reqDate = ((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear());
console.log(reqDate);

output

3/10/2014

Autres conseils

Given your clarification that you cannot change the format of the incoming date, you need something like this:

var dateParts = isoFormatDateString.split("-");
var jsDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2].substr(0,2));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top