0

I have an issue in my Laravel application.

The issue is that Internet Explorer is giving the wrong time compared to Firefox or Chrome in JavaScript.

My JavaScript Code:

console.log(expDate + ' --> ' + new Date(expDate).getTime() + " --> " + $.now());

It's output in Firefox:

09/25/18 4:31 PM UTC --> 1537893060000 --> 1537875054235

Output in IE:

09/25/18 4:31 PM UTC --> -1617866940000 --> 1537875062939

Can anyone help me with how to resolve the issue.

I want it so the new Date(expDate).getTime() gives the correct time in all browsers.

Any help will be appreciated.

Solution

My Issue was that new Date(expDate).getTime() was giving different timestamp in IE. So I solved my issue by to set date.

IE considers 09/25/18 4:31 PM UTC this date to 09/25/1918. Firefox considers 09/25/18 4:31 PM UTC this date to 09/25/2018.

So I just change the date format and picking exact date with exact years like 09/25/2018 4:31 PM UTC. So I get same result as in firefox.

Thanks

John Brad
  • 447
  • 1
  • 10
  • 26
  • Have you tried [momentjs](https://momentjs.com/)? What does `moment(expDate).format('YYYY-MM-DD');` say? Otherwise, [maybe this thread can help you](https://stackoverflow.com/questions/32837798/javascript-new-date-cross-browser-format-probleme). – Jeffrey Roosendaal Sep 25 '18 at 11:38
  • No, I am using simple JavaScript. I just need the correct time but IE making issue. – John Brad Sep 25 '18 at 11:40
  • Same Problem after trying your given thread. – John Brad Sep 25 '18 at 11:49
  • Then my suggestion would be to try momentjs. You can get it running in a couple of minutes, so I guess it's worth a try. I use it in almost every project, and never had any trouble with cross browser Date stuff. – Jeffrey Roosendaal Sep 25 '18 at 11:52
  • "09/25/18 4:31 PM UTC" is not a format supported by ECMA-262, so parsing is implementation dependent. To get consistent results, parse using a bespoke function or a library, avoid the built-in parser. For the record, Safari returns `1537893060000`. – RobG Sep 25 '18 at 22:11
  • Thanks @Jeffrey Roosendaal to help me. – John Brad Sep 27 '18 at 11:30

0 Answers0