Created
February 28, 2017 14:58
-
-
Save mikepenzin/6258ba0261c12d83580756efe207ecec to your computer and use it in GitHub Desktop.
Display Date & Time
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
// 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