an iPhone client send a date to a Java server as Apple’s Cocoa framework Epoch (which the ms since 2001) and when you converted to java date (since 1970) it convert as 1980 for the year 2011, is adding 30 year to Cocoa date will converted ? or is there any other methode that i could use for this conversion ?
Share
I would recommend adjusting the seconds to the Unix epoch time (since 1970) by adding the appropriate number of seconds, instead of bumping up the year. I’m not positive, but my instincts tell me that bumping the year itself will be wrong in some cases (with leap years and small adjustments to the calendar, etc).
If you need to add seconds to seconds since Jan 1 2001, the number you’re looking for is +978307200. If you need millis, just multiply by 1000.
As an example, I had some code that needed to detect Apple vs Unix epoch dates in seconds since epoch, and convert them into Java Dates that took milliseconds since Unix epoch in the constructor: