0

I was testing my new SharePoint list. One of my list item entries is based on Date();. When I enter the data into Chrome, it has the "GMT-0500 (Eastern Standard Time)" and in IE, the GMT is not there. Is there away to strip the GMT in Chrome?

0

It seems the default behavior since the implementation of date parse function differs across browsers.

Chrome assumes they're in UTC while IE assumes they're local to the user.

Please see the similar posts below.

Chrome does not return correct hour in javascript.

Different values with Date() in Chrome and IE.

0

As you look into it more I think you'll find that there are many differences that can be found between how different browsers and operating systems report new Date().toString(). For that reason I wouldn't try and come up with code myself that solves the problem because there will be some edge cases that you just won't catch. So looking at things that people way smarter than me have done I would recommend one of the following.

Depending upon your need maybe you could use toDateString() or toISOString(). Documentation here and here.

If those won't meet your needs then perhaps using a library like moment.js which allows for all kinds of date related manipulations. We have used moment.js and like it, but here is a list of other date manipulation libraries.

  • Thanks. I tried the toDateString and I got the consistent entries. The only issue is I need the time stamp. So, I just used the toString function to convert the Date to a string, spliced, concatenated, then create the time stamp I wanted. It worked, but your warning on not trying to come up with my own code is weighing heavily on my mind...I may just have to use the toDateString and that's it. – adams-j Nov 12 at 14:45
  • Ah, didn't mean to be too scary. If toDateString() works for the date part and all you need to do is add the time part you can probably get away with that. It is if you are planning to do a bunch of manipulations or to manipulate the toString() version that I recommend not trying to roll your own. – Rothrock Nov 12 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.