Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 731 Bytes

how-to-get-format-date-in-yyyy-mm-dd.md

File metadata and controls

27 lines (21 loc) · 731 Bytes

How to get format date in "yyyy-mm-dd"

const d = new Date("10/07/2022").toLocaleDateString("en-gb").split('/');
const date = d[2] + '-' + d[0] + '-' + d[1];
  • new Date("10/07/2022") - create date object with given date
  • toLocaleDateString - returns locally formatted date string
  • "en-gb" - use this locale to get date in m/d/y format
  • d[2] + '-' + d[0] + '-' + d[1] - assemble date components to single string
  • date - will contain date in YYYY-MM-DD format

group: date

Example:

const d = new Date("10/07/2022").toLocaleDateString("en-gb").split('/');
const date = d[2] + '-' + d[0] + '-' + d[1];
console.log(date);
2022-07-10

link_youtube: https://youtu.be/gOA16QGJU_s