Skip to content

Instantly share code, notes, and snippets.

@peppapig13132
Created January 27, 2024 06:55
Show Gist options
  • Save peppapig13132/f374b9b90c4def24755cbdd1bd330eaf to your computer and use it in GitHub Desktop.
Save peppapig13132/f374b9b90c4def24755cbdd1bd330eaf to your computer and use it in GitHub Desktop.
JavaScript new Date() Returns NaN or is Blank in Safari

JavaScript new Date() Returns NaN or is Blank in Safari

ISO formatted Date is not supported on Safari.

const date = new Date('2021-08-09');   // yyyy-mm-dd 

Alternaive Date formats

const nDate = new Date('2021, 07, 06'); // yyyy, mm, dd
const nDate = new Date(2021, 07, 06, 10, 05, 00); // yyyy, mm, dd, hh, mm, ss
const nDate = new Date(07/06/2021); // mm/dd/yyyy
const nDate = new Date(07/06/2021 10:05:00); // mm/dd/yyyy hh:mm:ss
const nDate = new Date(1625600237781); // milliseconds
const nDate = new Date(Tue Jul 06 2021 10:05:00); // Day Mon dd yyyy hh:mm:ss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment