0

within my Angular app : i'm receiving this format date from webservice :

myDate = "2020-03-05T08:00:00"

-> for me it's the fifth march 2020

-> for chrome , firefox , IE it's alse the same format yyyy-mm-ddThh:mm:ss

But for Safari , it seems to confuse it with :

yyyy-dd-mmThh:mm:ss

-> and it reads it as it's the 3rd My 2020

****Am i alright ?****

My purpose is to get the time and i'm using to do new Date(myDate)

should i do it differently with Safari ?

firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
  • Don't let the browsers decide, reformat it yourself at the start of your script – Alexandre Elshobokshy Mar 05 '20 at 08:20
  • You can try `momentJs` `startDate = moment('2015-07-06 08:00', 'YYYY-MM-DD HH:mm').toDate();` for formating – Rohit.007 Mar 05 '20 at 08:53
  • "2020-03-05T08:00:00" **should** be treated as local, but Safari gets it wrong and treats it as UTC. Rule 1 with Date objects: do not rely on the built–in parser. Manually parse strings or use a library. – RobG Mar 06 '20 at 06:55

1 Answers1

-1

Either you can use the default Javascript Date Functionality like

const newDate = new Date(myDate) fetch the date, day , month and create your date

Or you can use moment.js libaray to directly format your newDate object, in whatever format you like

Or if you are using specifically angular, then for rendering you can use the date pipe of angular and format it accordingly.

vishal
  • 137
  • 1
  • 7
  • The OP's issue is that the built–in parsers in different implementations give different results, so "*use the default Javascript Date Functionality*" does not work. :-( – RobG Mar 06 '20 at 06:53