Skip to content

Instantly share code, notes, and snippets.

@talkingnews
Last active November 20, 2018 12:36
Show Gist options
  • Save talkingnews/63ae7cb8ef758e6a487bb87f83477b87 to your computer and use it in GitHub Desktop.
Save talkingnews/63ae7cb8ef758e6a487bb87f83477b87 to your computer and use it in GitHub Desktop.
Various useful javascript date and time formats
// 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