Discrepancy in Timestamp Deviation for Older Dates Between Java and Javascript (1 Hour)

When I try to convert a string date representation to numeric values, I noticed a discrepancy between Java/Groovy/PHP and Javascript. Specifically, for certain dates before 1970, the JS timestamp is exactly 3600 seconds behind the Java timestamp. This issue was reproducible for October 1st, but not for January 1st.

Here is an example test case in Groovy using the Java API:

def sdf = new SimpleDateFormat("dd/MM/yyyy")
["01/10/1956", "01/01/1956", "01/10/1978"].each {
    def d = sdf.parse(it)
    println "${it} -> ${d.time}"
}

And in JavaScript (run in Chrome console - "9" indicates October):

new Date(1956, 9, 1, 0, 0, 0).getTime()

Sample results:

*Groovy

  1. 01/10/1956 -> -418179600000
  2. 01/01/1956 -> -441853200000
  3. 01/10/1978 -> 276040800000

*Javascript

  1. 1956,9,1,0,0,0 -> -418183200000
  2. 1956,0,1,0,0,0 -> -441853200000
  3. 1978,9,1,0,0,0 -> 276040800000

It's interesting to note the 3600 seconds difference for the date 01/10/1956.

I considered daylight saving time or timezone differences as potential causes, but I am still puzzled by the divergence between the two environments in the past.

Any insights would be appreciated!

Thank you

EDIT additional samples

*Java/Groovy

01/01/1974 -> 126226800000
01/10/1974 -> 149814000000
01/01/1976 -> 189298800000
01/10/1976 -> 212972400000
01/01/1978 -> 252457200000
01/10/1978 -> 276040800000    

*JS

new Date(1974, 0, 1, 0, 0, 0).getTime()    126226800000
new Date(1974, 9, 1, 0, 0, 0).getTime()    149814000000
new Date(1976, 0, 1, 0, 0, 0).getTime()    189298800000
new Date(1976, 9, 1, 0, 0, 0).getTime()    212972400000
new Date(1978, 0, 1, 0, 0, 0).getTime()    252457200000
new Date(1978, 9, 1, 0, 0, 0).getTime()    276040800000

Between 1967-1971

01/01/1967 -> -94698000000
01/04/1967 -> -86922000000
01/10/1967 -> -71110800000    
01/01/1968 -> -63162000000
01/04/1968 -> -55299600000
01/10/1968 -> -39488400000
01/01/1971 -> 31532400000
01/10/1971 -> 55119600000

new Date(1967, 0, 1, 0, 0, 0).getTime()   -94698000000
new Date(1967, 3, 1, 0, 0, 0).getTime()   -86925600000
new Date(1967, 9, 1, 0, 0, 0).getTime()   -71114400000
new Date(1968, 0, 1, 0, 0, 0).getTime()   -63162000000
new Date(1968, 3, 1, 0, 0, 0).getTime()   -55303200000
new Date(1968, 9, 1, 0, 0, 0).getTime()   -39492000000
new Date(1971, 0, 1, 0, 0, 0).getTime()   31532400000   
new Date(1971, 9, 1, 0, 0, 0).getTime()   55119600000   

Answer №1

Your profile indicates you hail from Belgium.

In 1976, Brussels did not observe daylight saving time:

However, starting from 1977, daylight saving time is observed:

It's likely that Java is cognizant of this difference, whereas JavaScript is not.

Answer №2

The topic of Timezones is surprisingly intricate, with the constant changes and inaccuracies that often arise.

Exploring this concept in Java/Groovy would be a good idea.

new Date(1956, 9, 1, 0, 0, 0).getTime()

Here is an interesting website discussing timezones:

For instance, the epoch is set at 1970/01/01 00:00 UTC, not Europe/London due to the UK being in BST (British Summer Time) during winter between February 1968 and November 1971. :P

As you delve deeper into the world of time and date, you will realize how arbitrary it all seems. Even UTC, which stands for "Coordinated Universal Time" in English and "Temps Universel Coordonné" in French, was a compromise as they couldn't agree on the acronym. It's a fascinating topic! http://en.wikipedia.org/wiki/Coordinated_Universal_Time

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

Is there a method to incorporate JS code from one JS file into another JS file within a NodeJS application?

Currently, I am in the process of developing a web application using NodeJS. The basic idea behind my approach is to have a primary structure where different tools can be added based on specific requirements for the app. My challenge lies in having my mai ...

Manipulating arrays within Vuejs does not trigger a re-render of table rows

I have successfully generated a user table using data retrieved from an ajax request. The table has a structure similar to this: [Image of Table][1] Now, when an admin makes changes to a user's username, I want the respective row to update with the n ...

Unending cycle occurs when utilizing a computed property alongside Vue Chart js

My goal is to refresh my chart with new data from an API call every 5 seconds. However, the chart is updating excessively, rendering each point hundreds of times. After checking the logs, I discovered that there seems to be an infinite loop causing this is ...

Index similar to JavaScript-Meadow

Is there a way to create a table of contents like the ones seen on sites such as JavaScript Gardens? How do they determine which section is currently active and are there any recommended JavaScript libraries that can help achieve this functionality? Edit: ...

Utilizing data retrieval caching in nextjs getServerSideProps() for optimized performance

I am currently developing an application using nextjs that retrieves data from a firebase firestore. The issue I am facing is that the application makes these requests on every page load, even when the data does not need to be completely up to date. To add ...

Fetching information from WebMethod with Jquery Ajax in c#

I have a jQuery variable that contains the following values: var data = [['Vikas', 75], ['Sumit', 55], ['Rakesh', 96], ['Shivam', 123], ['Kapil', 34], ['Rana', 104]]; Now, according to my requir ...

What is the process for creating a folder using Firebase Cloud Functions with Storage?

How do I create a folder named "posts"? Storage bucket path --> gs://app.appspot.com/posts Code to generate thumbnail from storage object exports.generateThumbnail = functions.storage.object() .onChange(event => { const object = event.data ...

What is the best way to move between websites or pages without having to reload the current page using a selector?

Have you ever wondered how to create a webpage where users can navigate to other websites or pages without seeing their address, simply by selecting from a drop-down menu? Take a look at this example. Another similar example can be found here. When visit ...

Discovering the magic of nesting maps in React-Native without the need for

I am currently developing a react-native app that retrieves its data through an API. I am working on implementing a new feature where the information is grouped by date. The JSON data structure sent by the API looks like this: { "channel_count" ...

Issue with Braintree drop-in form: Nonce string generation problem

I've encountered a peculiar issue while trying to utilize the dropin form from Braintree. Successfully integrating the form into a view, here's how it looks: <form id="createTransactionForm" method="post" action="#&qu ...

A guide on how to automatically preselect a RadioGroup option in Material-UI

When a user selects an option from the MCQ Select using RadioGroup in my code and submits it, they should be able to return later and see the option they selected highlighted, similar to how Google Forms allows users to review their selections. Below is t ...

The android camera app encountered a java.lang.RuntimeException when trying to instantiate the activity ComponentInfo

Trying to create a custom Android app using the Android Developer site and Android Studio, but encountering errors when running the app in the emulator. The error message received is: java.lang.RuntimeException: Unable to instantiate activity ComponentInf ...

Unable to dynamically attach a class in Vue.js

I have exhausted all possible variations of this issue. I meticulously followed the official Vue guides, consulted numerous stack overflow posts, and went through various tutorials. I experimented with different syntaxes, quotations, array structures, and ...

The Invalid_grant OAuth2 error occurs when attempting to access the Google Drive API using

SOLVED! The issue was resolved by correcting the time on my Linux Server. Google's server was blocking access due to incorrect time settings. I used the following command on my Server to synchronize the time: ntpdate 0.europe.pool.ntp.org Original P ...

transferring function from server to the client module named Next 13

After referencing the documentation for the app directory in Next.js, it is recommended to fetch data inside Server Components whenever feasible. Server Components always carry out data fetching on the server. This advice is particularly helpful for me as ...

creating a post action using Node.js with Express and Angular

Process Overview I have an Angular post that communicates with my Node.js Express backend to send data to an API. My goal is to redirect the user to a different Angular page upon successful post, or display an error message if the post fails. One approac ...

Customize your MUI Select to show the selected value in a different way within the Input field

I have a collection of objects and I am looking to link multiple attributes of the object in MenuItem, but I only want one attribute to be displayed in Select https://i.sstatic.net/kDKLr.png The image above displays "10-xyz" in the select display, when i ...

Encountered difficulty locating the module path 'stream/promises'

When importing the following in a typescript nodejs app import { pipeline } from "stream/promises"; Visual Studio Code (vscode) / eslint is showing an error message Unable to resolve path to module 'stream/promises' https://i.sstatic. ...

How can I assign a default value for a multiple select dropdown list in AngularJS?

I am currently facing an issue with my multiselect dropdown. The code for the dropdown is as follows: <select id="year" multiple ng-model="type" ng-disabled="!type1" > <option value="all" selected>all</option>; <option value= ...

The state in the React components' array functions is not current

import React, { useState } from "react"; const Person = ({ id, name, age, deleteThisPerson }) => { return ( <div className="person"> <p>{name}</p> <p>{age}</p> <button onClick ...