Created
November 25, 2017 20:01
-
-
Save rsarai/d58c21c803b8b08ec39abef6165d911f to your computer and use it in GitHub Desktop.
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
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