Last active
November 20, 2018 12:36
-
-
Save talkingnews/63ae7cb8ef758e6a487bb87f83477b87 to your computer and use it in GitHub Desktop.
Various useful javascript date and time formats
This file contains hidden or 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
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString | |
const startDate = new Date() | |
//2018-11-20T11:33:57.788Z | |
const yyyymmdd = startDate.toISOString().slice(0, 10); | |
//'2018-11-20' | |
const startTimeWithSeconds = startDate.toLocaleTimeString(); | |
//'11:33:57 AM' | |
const startTimeWithoutSeconds = startDate.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}); | |
//'11:37 AM' | |
const fullStartTime = startDate.toLocaleTimeString([],{weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); | |
//'Tuesday, November 20, 2018, 11:33:57 AM' | |
const fullStartDateWithoutTime=startDate.toLocaleDateString([],{ weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) | |
//'Tuesday, November 20, 2018' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment