문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top