Created
January 18, 2012 22:05
-
-
Save matharchod/1636100 to your computer and use it in GitHub Desktop.
A jQuery date script that appends the current date & time to a DOM element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showDateIn(elem) { | |
var date = new Date(); | |
var today = date.toLocaleDateString(); | |
var hours = date.getHours(); | |
var minutes = date.getMinutes(); | |
var ampm; | |
if (minutes < 10) { | |
minutes = "0" + minutes; | |
} | |
if (hours == 12) { | |
ampm = "PM"; | |
} else if (hours > 11 && hours != 12) { | |
ampm = "PM"; | |
hours = hours - 12; | |
} | |
else { | |
ampm = "AM"; | |
} | |
var time = hours + ":" + minutes + " " + ampm; | |
$(elem).append(today + " @ " + time); | |
} | |
showDateIn('#div'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment