• 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

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

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