Currently I am trying to convert a date calculation from javascript to java, since I want to use it for Android development. So in javascript I was using the method date.valueOf()
, which converts the date to the milliseconds that passed since January 1, 1970. In java the method with the same funcionality is called date.getTime()
. In the java and javascript documentation the description is exactly the same, but when I am inserting the same date, I am getting two completely different values.
For example:
Java getTime()
Date date = new Date(2011, 10, 1);
System.out.println(date.getTime()); //prints: 61278249600000
Javascript valueOf()
const date = new Date(2011, 10, 1);
console.log(date.valueOf()); //prints: 1320102000000
So my questions are:
- Why is this happening? (or what did I wrong?)
- How can I correct the code?
It would be awesome if somebody can help me.