0

I want the date&time to be in this format. For example

2012/3/21 23:47:01 2011/11/23 19:33:02

Is it make use of java script? Any source code or tutorial help? Many thanks!

08091 Yin
  • 119
  • 1
  • 3
  • 13
  • 1
    Possible duplicate - http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript – Chirag Mar 21 '12 at 04:06

1 Answers1

7

This article may be dated, but it should still do the trick http://www.tizag.com/javascriptT/javascriptdate.php

To return the current date, you can use something like:

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)

And to return the time you can use something like:

var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}​
Ryan
  • 2,433
  • 5
  • 31
  • 41