setGregorianChange
only changes the point in time where the switch from Julian to Gregorian happened. It defaults to the correct historical value.
But since pretty much everyone else out there is using proleptic Gregorian, there is a valid use case for this function:
setGregorianChange(new Date(Long.MIN_VALUE)) //Julian never happened
This is also what JodaTime uses by default.
Anyway, you can just subtract 946684800000L
from the normal millisecond unix timestamp, and divide by 1000:
public static long secondsSince2000(Date input) {
final long epoch = 946684800000L;
return (input.getTime() - epoch) / 1000L;
}
To convert from seconds since 2000:
public static Calendar fromSecondsSince2000( long seconds ) {
final long epoch = 946684800000L;
Calendar cal = GregorianCalendar.getInstance();
long timestamp = epoch + seconds * 1000L;
cal.setTime(new Date(timestamp));
return cal;
}
To see that both are working:
long sec = secondsSince2000(new Date());
Calendar cal = fromSecondsSince2000( sec );
System.out.println(cal.getTime().toString().equals(new Date().toString()));
They should print true