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
- 01/10/1956 -> -418179600000
- 01/01/1956 -> -441853200000
- 01/10/1978 -> 276040800000
*Javascript
- 1956,9,1,0,0,0 -> -418183200000
- 1956,0,1,0,0,0 -> -441853200000
- 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