0

I have the following date time 2012-05-01T00:00:00T+01:00

Is this a standard date time format? It seems to have a timezone in the end. So it doesnt seem to be either ISO 8601 or UTC ?

How do I output this in Javascript for todays date ?

32423hjh32423
  • 3,048
  • 7
  • 44
  • 59
  • 1
    It is in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC) format. The `+01:00` is the time offsets from UTC, see also the documentation link. – Igor Apr 29 '21 at 14:37
  • 1
    `How do I output this in Javascript for todays date ?` ← Do you mean you want this same format for the current date/time? – Igor Apr 29 '21 at 14:39
  • @Igor yes please – 32423hjh32423 Apr 29 '21 at 14:40
  • 2
    Does this answer your question? [How to ISO 8601 format a Date with Timezone Offset in JavaScript?](https://stackoverflow.com/questions/17415579/how-to-iso-8601-format-a-date-with-timezone-offset-in-javascript) – Igor Apr 29 '21 at 14:41
  • 1
    Although this doesn't directly answer your question, JS datetime implementations and string representations vary from browser to browser, so I recommend that instead of relying on those outputs you use a lightweight Date library like Luxon, which allows you to manipulate datetimes and output them in a specific format. https://moment.github.io/luxon/ – Nisala Apr 29 '21 at 15:04

1 Answers1

-1

There are several options for you


let inputFormat = "2012-05-01T00:00:00T+01:00"

let customDateFormat = new Date(sample.split("+")[0].split("T").join(" "))

OR best way => moment.js


let inputFormat = "2012-05-01T00:00:00T+01:00"

let customDateFormat = moment(sample.split("+")[0].split("T").join(" ")).format("DD/MM/YYYY")

Sudarshan
  • 702
  • 6
  • 24