Skip to content

Instantly share code, notes, and snippets.

@amazingandyyy
Last active December 17, 2019 22:07
Show Gist options
  • Save amazingandyyy/489e9ac301a5022e6e8c60236df7e875 to your computer and use it in GitHub Desktop.
Save amazingandyyy/489e9ac301a5022e6e8c60236df7e875 to your computer and use it in GitHub Desktop.
const unix = Date.now()
const d = new Date(unix);
// try out
console.log('toDateString ', d.toDateString())
console.log('toTimeString ', d.toTimeString())
console.log('toLocaleDateString', d.toLocaleDateString())
console.log('toLocaleTimeString', d.toLocaleTimeString())
console.log('getMonth', d.getMonth())
console.log('getDate', d.getDate())
console.log('getHours', d.getHours())
// want 3-20 at 6pm
function getHoursIn12(hour) {
if(hour>12){
return `${hour-12}pm`
}
return `${hour}am`
}
console.log(`${d.getMonth()+1}-${d.getDate()} at ${getHoursIn12(d.getHours())}`) // 12-17 at 2pm
console.log(`${d.getMonth()+1}-${d.getDate()} at ${d.toLocaleTimeString()}`) // 12-17 at 2:06:47 PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment