When provided with varied inputs, new Date() yields distinct values for various time zones

var date1 = "2015-03-29";
console.log(new Date(date1)); //Output:Sun Mar 29 2015 05:30:00 GMT+0530 (India Standard Time)

var date2 = "1869-12-31";
console.log(new Date(date2)); //Output:Fri Dec 31 1869 05:53:20 GMT+0553 (India Standard Time)

var date3 = "1870-01-01";
console.log(new Date(date3)); //Output:Sat Jan 01 1870 05:21:10 GMT+0521 (India Standard Time)

While troubleshooting some Date() related issues, I observed the unusual behavior of Date() with different input values.

Interestingly, the time zones differ for each of the three inputs despite my System's time zone being GMT +05:30

Is this an expected outcome?

Appreciate any assistance in advance!

Answer №1

The data you have displayed is accurate.

According to the ECMAScript specifications, date-only values in the YYYY-MM-DD format are considered UTC by default. This information can be found in the technical specification:

... When there is no UTC offset representation, date-only forms are interpreted as UTC time, while date-time forms are interpreted as local time.

Subsequently, the toString function converts the value into a string representation of local time, factoring in the system's time zone settings.

Detailed IANA time zone data for India, along with descriptive comments, can be accessed from here. The current data (based on tzdata version 2021a) is as follows:

# Zone  NAME            STDOFF    RULES    FORMAT    [UNTIL]
Zone    Asia/Kolkata    5:53:28   -        LMT       1854 Jun 28  # Kolkata
                        5:53:20   -        HMT       1870         # Howrah Mean Time?
                        5:21:10   -        MMT       1906 Jan  1  # Madras local time
                        5:30      -        IST       1941 Oct
                        5:30      1:00     +0630     1942 May 15
                        5:30      -        IST       1942 Sep
                        5:30      1:00     +0630     1945 Oct 15
                        5:30      -        IST

In your example, you can observe two earlier offsets mentioned in the second and third lines of data. By selecting an even older date (prior to 1854-06-28), you will encounter the offset indicated in the first line. It is also evident that India utilized a +06:30 offset during distinct historical periods.

You can refer to a more user-friendly presentation of all historical data at timeanddate.com here.

This explanation highlights the dynamic nature of time zones. They do not adhere to a fixed numerical offset; instead, the offset varies based on the specific point in time within a time zone, subject to changes directed by the governing authority overseeing that region. For further insights, consult the section titled "Time Zone != Offset" within the timezone tag wiki.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Warning in Next.js: When utilizing conditional rendering, the server HTML is expected to have a corresponding <div> inside another <div>

Although similar questions have been asked on various platforms like Google, none seem to provide answers that align with my specific situation. Essentially, my goal is to have a different search bar displayed in the header based on the page I am currentl ...

How can I transfer data from an API response containing an array of objects to a new array in a Vue.js

How come I am getting NaN instead of "qwe" and "qweqweqwe" when trying to push the first 6 elements from an array of objects to a new array? Imagine the array of objects retrieved from the API is structured like this: 0: {id: 340, name: "qwe", lastname: ...

What is the best way to recover past messages from a channel?

I am working on a bot that is supposed to be able to retrieve all messages from a specific server and channel upon request. I attempted to use the channel.messages.cache.array() method, but it only returned an empty array []. How can I efficiently fetch ...

What is the Best Way to Ask Users Not to Delete Local Storage Information?

As I work on developing an application using angularJS, the need to save data locally has arisen. To achieve this, I am utilizing HTML5 local storage. One challenge faced with HTML5 local storage is that when a user clears their browsing data, all stored ...

Tips for setting up a range slider for decimal numbers

I have implemented the following code for a range slider. It works perfectly fine for integer values like 1 and 100, but I am facing issues when trying to use decimal values. I attempted to substitute 1 with 0.1 but it did not yield the desired result. ...

Tips on redirecting a user to a specific page after they have made a selection without doing so immediately

I am a beginner in the world of coding. Currently, I am working on creating templates for an online software application. Users will have the option to select from different choices using radio buttons. However, I want to ensure that users are not redirect ...

The command 'node' is not being recognized as either an internal or external command, potentially due to it being an operable program or batch file. This issue only arises when attempting to

Whenever I try to npm install a package or check the node/npm version, it works fine. However, upon attempting to start the app with any scripts, I encounter the following error message. [EDITED] $ npm start > <a href="/cdn-cgi/l/email-protection" ...

Incorporate Calendly Script into your NextJs application

I'm currently working on integrating Calendly into my Next.js project. However, I am unsure about the process. My goal is to embed it on a specific page rather than in _app or _document. Here is what I have attempted so far: import Script from &apos ...

Removing an item from an ng-repeat loop while also dealing with a FormController within

I am encountering a significant issue with form inputs nested within the ng-repeat directive. I require an input that is an array and can vary in size; allowing users to add or remove parts of the form. Within the ng-repeat directive, there is an ng-form ...

Effective strategies for managing form submissions with React and Typescript

As I dive into refactoring my code to TypeScript, especially as I am still getting accustomed to it, I find myself pondering about the HTML element types with React events. This has led me to rethink how I approach form creation and submission event handli ...

Ways to bypass a transition using JavaScript

Hello everyone, I would like to start by apologizing for any mistakes in my English. I have been working on a website, which is currently available here: As you scroll down, the height of the image below the menu decreases. I am trying to make the navig ...

Storing information when an object is indexed in a for loop, to be retrieved later when

My JavaScript code includes an AJAX call that takes user input from a form and uses it to search for a JSON object. The matching objects are then displayed in a datalist successfully. Everything is working well so far, but now I want to extract specific f ...

empty responseText from GET request using AJAX

I've been working on a chatbox using AJAX and I've encountered an issue where my xhttp.responseText is coming back empty. In firebug, I can see that the GET request is being sent and the correct text is being returned, but for some reason it&apos ...

Retrieve the database value for the chosen name and then add that name to a different table

I am working on a dropdown feature that fetches categories from a database and displays the selected category price in a textfield. For example, when 'web development' is selected, the price ($12) will display in the textfield. Below is the cod ...

execute bower install for the specified bower.json file

Let's say my current working directory is c:\foo\ while the script is running. I want to execute bower from there for the c:\foo\bar\bower.json file. This can be done in npm by using npm install --prefix c:\foo\bar. ...

Steps to retrieve the value of a particular row in a table using vuejs

Can you help me retrieve the value of a specific row in a table using VueJS 2? Here is an image of my current table: I need assistance with obtaining and displaying the last value from a loop in the "SHOW QR Button" within my code snippet. The button shou ...

Transform JSON data into a Google Sheet using Google Apps Script

Having trouble inserting the JSON response into Google Sheet using Google Apps Script with the code below. Running into errors, even though I can't seem to pinpoint the issue. Take a look at the screenshot and code snippet provided: function myF ...

Using Selenium Webdriver to simulate pressing ‘ctrl + t’ for opening a new tab in Javascript

I have been utilizing Selenium Webdriver to conduct testing on a web application that is currently undergoing development. Despite having developed multiple tests already, I am facing challenges in attempting to open new tabs within the window controlled b ...

Can't get className to work in VueJS function

I need help changing the classNames of elements with the "link" class. When I call a method via a click action, I can successfully get the length of the elements, but adding a class does not seem to work. Does anyone have any insights into this issue? HTM ...

Is it possible to access prop properties within the ready() function?

I am seeing the error message undefined in the console, specifically originating from the ready() function. The issue I am encountering is related to attempting to assign the value of this.users.name to this.userForm.name. Can someone please point out wh ...