I am using the JodaTime jar with Oracle Java 8. I receive packages from the firmware device and it starts on January 1, 2000. I need to get the second number from January 1, 2000. The math seems simple, but for some reason it gives me a negative value that comes out at that time in 1999, and not at the current time:
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
public class TimeIssue {
private DateTime currentTime = DateTime.now(DateTimeZone.UTC);
private DateTime zeroPointTime = new DateTime(2000, 1, 1, 0, 0, DateTimeZone.UTC);
private void checkTime(){
System.out.println("current time: " + currentTime);
System.out.println("current time to secs: " + timetos(currentTime));
}
private int timetos(DateTime time){
return (int)(time.getMillis() - zeroPointTime.getMillis())/1000;
}
public static void main(String[] args) {
TimeIssue issue = new TimeIssue();
issue.checkTime();
}
}
output:
current time: 2014-07-09T21:28:46.435Z
current time in seconds: -1304974
current time from seconds: 1999-12-16T21:30:26.000Z
I would suggest that it subtracts the current time in milliseconds since 2000 in milliseconds, and dividing by 1000 will give me the current time in seconds since 2000, but it gives me a negative number. What can i do wrong?
source
share