0

I have a UTC Date as follows: Mon Aug 30 2021 00:00:00 GMT-0400 (Eastern Daylight Time)

Is there any jQuery or JavaScript function that converts the UTC date string to mm/dd/yyyy format?

I searched high and low and cannot find anything. Thanks!

H. Ferrence
  • 7,906
  • 31
  • 98
  • 161
  • 2
    You mean [DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat)? That's almost literally the first example =) (also note that for custom schemes, the [.format()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format) function's got you covered) – Mike 'Pomax' Kamermans Aug 19 '21 at 18:05
  • 1
    you need somthing like ``` new Date("Mon Aug 30 2021 00:00:00 GMT-0400").toLocaleDateString()``` checkout https://css-tricks.com/everything-you-need-to-know-about-date-in-javascript/ – Moufeed Juboqji Aug 19 '21 at 18:07
  • Thanks @Mike'Pomax'Kamermans -- that answered the question!! – H. Ferrence Aug 19 '21 at 18:08
  • Moufeed, Solomon: remember not to put code answers (even if they're questionable answers) in comments. Write an answer, and explain why you gave that specific code. – Mike 'Pomax' Kamermans Aug 19 '21 at 18:09
  • I've vote to close this one (if you don't delete it first =) as it's already covered by the standard JS docs for working with dates. – Mike 'Pomax' Kamermans Aug 19 '21 at 18:09
  • I put it as an answer –  Aug 19 '21 at 18:12
  • "Mon Aug 30 2021 00:00:00 GMT-0400 (Eastern Daylight Time)" is not a "UTC Date" in any respect, it's a timestamp in the format produced by [*Date.prototype.toString*](https://262.ecma-international.org/#sec-date.prototype.tostring). UTC is a time standard that does not specify formats. – RobG Aug 20 '21 at 03:46

1 Answers1

1

you can use Date.parse and Intl.datetimeformat as in

console.log(new Intl.DateTimeFormat('en-US').format(Date.parse("Mon Aug 30 2021 00:00:00 GMT-0400 (Eastern Daylight Time)")));
  • You really shouldn't answer questions that have been asked many, many times before (there are over 130 answers across the marked duplicates that the OP can learn from). Mark them as duplicates. If the OP has trouble applying the duplicate to their question, they can ask another question with what they're having trouble with. – RobG Aug 20 '21 at 03:52