Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  132] [ 1]  / answers: 1 / hits: 50095  / 12 Years ago, wed, march 21, 2012, 12:00:00

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!


More From » html

 Answers
19

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)
}​

[#86705] Monday, March 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;