Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:52:21+00:00 2026-06-06T06:52:21+00:00

I tested the following code in firefox scratchpad and got interesting result? var date=new

  • 0

I tested the following code in firefox scratchpad and got interesting result?

var date=new Date("2012-05-12");
var date2 = new Date("05/12/2012");
date;
/*
Fri May 11 2012 17:00:00 GMT-0700 (Pacific Daylight Time)
*/
date2;
/*
Sat May 12 2012 00:00:00 GMT-0700 (Pacific Daylight Time)
*/

Two dates are different. Apparently this is due to the timezone issue. What I want is date2 result. How can I make js engine correctly treats the ISO date style?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:52:23+00:00Added an answer on June 6, 2026 at 6:52 am

    I think the issue is that the string “2012-05-12” is taken to be an ISO 8601 date, while “05/12/2012” is an RFC 2822 date. In the ISO format, the lack of a timezone implies UTC. At midnight on the morning off May 12, in California (or wherever you are) it’s 7 PM the previous evening.

    The RFC date without a time zone, however, is parsed under the assumption that you want the timestamp for midnight in your local timezone. (Well, not necessarily your timezone; the timezone of the computer where your JavaScript runs 🙂

    You can see the difference if you pass those strings to Date.parse().

    The RFC date format can include an explicit time zone, but the ISO format cannot. (Well, it can, but browsers don’t pay attention, and apparently IE doesn’t handle those at all.)

    edit — here’s a simple (dumb; no error checking) function that’ll give you a date from that 3-part ISO form:

    function isoDate( str ) {
      var rv = null;
      str.replace(/^(\d\d\d\d)-(\d\d)-(\d\d)$/, function(_, yr, mn, dy) {
        rv = new Date(parseInt(yr, 10), parseInt(mn, 10) - 1, parseInt(dy, 10));
      });
      return rv;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't following code work correctly in FireFox 3.6? I have tested in IE7,
Consider following JavaScript code (tested in Firefox): function f(a) { if (a == undefined)
I tested the following code in IE6, IE7 and IE8 with the same result:
I tested the following code in IE, Chrome, and Firefox and it does not
Please advise.. In the following code(Tested. Will work fine) public class Exp_Test { public
Would someone kindly explain why the following bit of code works, I've tested it
I'm using the following code to read an XML file - var xmlhttp; if
I tested the following code in FF 3.6 and IE 8. The former alerts
Why does the following code not work in Internet Explorer (I've only tested in
I've following code for file download: FileInfo fileInfo = new FileInfo(filePath); context.Response.Clear(); context.Response.ContentType =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.