Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date with Hawaii timezone makes invalid JavaScript date

For some reason, when I pass a date with a Hawaii time zone to JavaScript's Date() I get "invalid date", but any other time zone I don't. Is there a workaround for this?

var HAST = 'Wed, 31 Jul 2013 07:21:16 HAST';
var hawaiiTime = new Date(HAST);
console.log("Hawaii time: "+hawaiiTime);
// Hawaii time: Invalid Date

var PST = 'Wed, 31 Jul 2013 07:21:16 PST';
var pacificTime = new Date(PST);
console.log("Pacific time: "+pacificTime);
// Pacific time: Wed Jul 31 2013 09:21:16 GMT-0600 (MDT) 

jsFiddle

like image 230
inorganik Avatar asked Jul 31 '13 17:07

inorganik


1 Answers

RFC 2822 only supports North American UT Offsets (See Page 32).

"EST" / "EDT" /         ; Eastern:  - 5/ - 4
"CST" / "CDT" /         ; Central:  - 6/ - 5
"MST" / "MDT" /         ; Mountain: - 7/ - 6
"PST" / "PDT" /         ; Pacific:  - 8/ - 7

For everything else, you should use the numeric value relative to UTC or GMT. For HAST, this would be UTC-1000 (10 Hours before UTC):

var HAST = 'Wed, 31 Jul 2013 07:21:16 UTC-1000';

Fiddle

like image 68
Mike Christensen Avatar answered Sep 28 '22 10:09

Mike Christensen