Skip to main content
Syntax highlighting.
Source Link
Mateen Ulhaq
  • 27.9k
  • 21
  • 121
  • 155

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

const today = (function() { const now = new Date(); const month = (now.getMonth() + 1).toString().padStart(2, '0'); const day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 
const today = (function() { const now = new Date(); const month = (now.getMonth() + 1).toString().padStart(2, '0'); const day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

const today = (function() { const now = new Date(); const month = (now.getMonth() + 1).toString().padStart(2, '0'); const day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

const today = (function() { const now = new Date(); const month = (now.getMonth() + 1).toString().padStart(2, '0'); const day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 
changed let's to const
Source Link
Dexygen
  • 12.6k
  • 13
  • 87
  • 154

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

letconst today = (function() { letconst now = new Date(); letconst month = (now.getMonth() + 1).toString().padStart(2, '0'); letconst day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

let today = (function() { let now = new Date(); let month = (now.getMonth() + 1).toString().padStart(2, '0'); let day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

const today = (function() { const now = new Date(); const month = (now.getMonth() + 1).toString().padStart(2, '0'); const day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 
added 20 characters in body
Source Link
Dexygen
  • 12.6k
  • 13
  • 87
  • 154

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

let today = (function() { let now = new Date(); let daymonth = ("0"now.getMonth() + now1).getDatetoString()).slicepadStart(-2, '0'); let monthday = ("0" + (now.getMonthgetDate() + 1).toString().slicepadStart(-2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

let today = (function() { let now = new Date(); let day = ("0" + now.getDate()).slice(-2); let month = ("0" + (now.getMonth() + 1)).slice(-2); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 

The simplest solutions seem to overlook that UTC time will be used, including highly up-voted ones. Below is a streamlined, ES6, non-jQuery version of a couple of existing answers:

let today = (function() { let now = new Date(); let month = (now.getMonth() + 1).toString().padStart(2, '0'); let day = now.getDate().toString().padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`; })(); console.log(today); // as of posting this answer: 2019-01-24 
Source Link
Dexygen
  • 12.6k
  • 13
  • 87
  • 154
Loading