Skip to content

Instantly share code, notes, and snippets.

@hasibomi
Last active October 27, 2017 22:17
Show Gist options
  • Save hasibomi/b18e0bd46602c294671688e1852677f3 to your computer and use it in GitHub Desktop.
Save hasibomi/b18e0bd46602c294671688e1852677f3 to your computer and use it in GitHub Desktop.
Date time example for javascript
const currDateTime = Date.now();
const dateTime = new Date(currDateTime);
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
document.querySelector("body").append("Timestamp: " + currDateTime);
document.querySelector("body").append(", Date: " + dateTime.getDate());
document.querySelector("body").append(", Month: " + dateTime.getMonth());
document.querySelector("body").append(", Month name: " + months[dateTime.getMonth()]);
document.querySelector("body").append(", Year: " + dateTime.getFullYear());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment