Skip to content

Instantly share code, notes, and snippets.

@mikepenzin
Created February 28, 2017 14:58
Show Gist options
  • Save mikepenzin/6258ba0261c12d83580756efe207ecec to your computer and use it in GitHub Desktop.
Save mikepenzin/6258ba0261c12d83580756efe207ecec to your computer and use it in GitHub Desktop.
Display Date & Time
// Today is : Friday.
// Current time is : 4 PM : 50 : 22
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var a = new Date();
var hour = a.getHours();
console.log("Today is : " + days[a.getDay()]);
console.log("Current time is : " + getH(hour) + " " + a.getMinutes() + ":" + a.getSeconds());
function getH(h){
var hours = h;
if (hours > 12){
return ((hours == 24) ? (0 + " AM"):((hours - 12) + " PM"));
} else {
return ((hours == 0) ? (0 + " PM"):((12 - hours) + " AM"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment