0

I receive a date in string with date and time, but I need to convert this date and time to just date and in the following format "dd-mm-yyyy"

example timestamp in string "2023-01-12T15:51:43.345"

Reporter
  • 3,897
  • 5
  • 33
  • 47
  • `new Date("2023-01-12T15:51:43.345")` parses the date. You can then call the [`getDate`](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate), [`getMonth`](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth), and [`getFullYear`](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear) methods along with [`padStart`](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/padStart) to arrange it in the desired format. – Sebastian Simon Jan 17 '23 at 12:11
  • If you want to use [`toLocaleString`](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString), here are the language codes that produce `"12-01-2023"`: `ia`, `jv`, `mi`, `qu`, `rm`, `wo`. My suggestion: `new Date("2023-01-12T15:51:43.345").toLocaleString("ia", { dateStyle: "short" })`. `ia` is for [Interlingua](//en.wikipedia.org/wiki/Interlingua). – Sebastian Simon Jan 17 '23 at 12:18

0 Answers0