Skip to content

Instantly share code, notes, and snippets.

@tithi021
Last active June 18, 2018 16:23
Show Gist options
  • Save tithi021/0321ec5498ad45a54049e18ee2421e1e to your computer and use it in GitHub Desktop.
Save tithi021/0321ec5498ad45a54049e18ee2421e1e to your computer and use it in GitHub Desktop.
Display the current day and time - Javascript
var today = new Date();
var day = today.getDay();
var dayList = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Thursday'];
var hour = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var prepand = '';
if(hour >= 12) {
hour = hour - 12;
prepand = 'PM';
} else {
prepand = 'AM';
}
console.log('Current time is: ' + hour + ':' + minutes + ':' + seconds + ' ' + prepand);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment