Skip to content

Instantly share code, notes, and snippets.

@rsarai
Created November 25, 2017 20:01
Show Gist options
  • Save rsarai/d58c21c803b8b08ec39abef6165d911f to your computer and use it in GitHub Desktop.
Save rsarai/d58c21c803b8b08ec39abef6165d911f to your computer and use it in GitHub Desktop.
export function getDayOfWeek(date) {
const dayOfWeek = new Date(date).getDay();
return isNaN(dayOfWeek) ? null : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
}
export function getMonthName(date) {
const monthNumer = new Date(date).getMonth();
return isNaN(monthNumer) ? null : ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'][monthNumer];
}
var timestamp = 1511637943345;
var date = new Date(timestamp);
var hour = timestampDate.getHours();
var minutes = timestampDate.getMinutes();
var seconds = timestampDate.getSeconds();
//target output is Saturday, November 25, 2017, 16:25:43
console.log(`${getDayOfWeek(date)}, ${getMonthName(date)} ${date.getDay()}, ${date.getFullYear()}, ${hour}:${minutes}:${seconds}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment