0

I am passing an ISO string for instantiating a date, on some browsers the date is created with timezone offset and on some its created without it...

is the a way to get around this issue, maybe something which is uniform across all browsers.

I'm looking for a way to create the date exactly like it came from the server.

The example ISO date and function I am currently using

var isoDate = '2017-10-29T00:00:00';
var date = new Date(isoDate); // some browsers create with offset and some without

Thanks!

  • Have you had a look at moment.js? – MickRip Jan 08 '18 at 11:23
  • 1
    Why buy a cow when all i need is a glass of milk? –  Jan 08 '18 at 11:43
  • 1
    It is strongly recommended to not use the built-in parser. '2017-10-29T00:00:00' should be treated as local, but some will treat it as UTC (and some old browsers wont parse it at all). There are much smaller libraries than moment.js if all you want is parsing and formatting, such as [*Fecha.js*](https://github.com/taylorhakes/fecha). – RobG Jan 08 '18 at 12:17
  • @RobG I have gone `String.match(/\d+/)` and instantiated the date like so `new Date(s[0],s[1]-1,s[2],s[3],s[4],s[5])` - it seems to have done the job... –  Jan 08 '18 at 12:34

0 Answers0