• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

Javascript Date parsing UTC or Local?

June 29, 2020 by Webhead

When parsing a string in a javascript Date object, if you don’t set a time, the string is taken in as UTC. Then when retrieving it, it displays as local time.

new Date('2020-01-01');

will return “Tue Dec 31 2019 14:00:00 GMT-1000 (Hawaii-Aleutian Standard Time) {}” when the current time is after 10am HST.

However,

new Date('2020-01-01 00:00:00');

will return “Wed Jan 01 2020 00:00:00 GMT-1000 (Hawaii-Aleutian Standard Time) {}” anytime, even after 10am HST.

Obviously, this is due to timezones. This stack overflow gets into the nitty gritty details:

https://stackoverflow.com/questions/5619202/converting-a-string-to-a-date-in-javascript

Filed Under: Coding Tagged With: javascript

Primary Sidebar

Topics

502 apache apple bluehost bootstrap buddypress chrome cloudways cms css debug drupal eCommerce firebug firefox git goDaddy google google analytics google maps hacked hosting htaccess html html 5 icons IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php tinymce wordpress wpengine yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools