Javascript time format problem
I am having an issue with Javascript right now and a plugin named "JMonthCalendar". The problem is essentially that using the "Date(2011, 6, 6) will return information like this: "Wed Jul 06 2011 00:00:00 GMT-0500 (Central Daylight Time)". This will not 开发者_Python百科work, the plugin does not read this format.
I then tried to look up timestamps, but this is not what I want either: "1311742800000"
What I need is something like this: "2011-06-28T00:00:00.0000000"
Is there a pre-programmed function for this? If not, how would you propose that I could best do it?
Thank you for your help.
EDIT: Here is the website and page that is in question, I am testing it right now so if it seems odd, thats why. -- http://powerqualityuniversity.net/?d=registration&p=calendar
Try this:
<script type="text/javascript">
function leadingZero(number) {
return number < 10 ? "0" + number : number;
}
function formatDate(date) {
return date.getFullYear() + "-" +
leadingZero(date.getMonth()) + "-"+
leadingZero(date.getDate()) + "T" +
leadingZero(date.getHours()) + ":" +
leadingZero(date.getMinutes()) + ":" +
leadingZero(date.getSeconds());
}
alert("formatted date: " + formatDate(new Date(2011, 6, 6)));
</script>
It might not be the sexiest solution, but since Javascript afaik doesn't have any native date formatting functionality built in you need to implement them yourself.
精彩评论