In my application, I'm reading a String value from a file which represents a time in UTC format and is generated by .net 2015. In my application which is in Java, I read this value and need to convert it into a long value first and then convert it back to a UTC time. Here is my code in Java to convert time to long value:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = df.parse(timeString);
long timeLong = date.getTime();
and to convert it back to UTC format:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = new Date(timeLong);
newTimeStamp = df.format(date);
However, the final UTC time I get is not the same as the original time I read from file. It has almost two hours difference. I want to know whether it is because of the difference in implementation of time conversion in Java and .Net.
My original time is 2015-12-22T21:00:11.8701036Z
and the final time I get after doing this conversion is 2015-12-22T23:25:12.000036Z
.
p.s. I'm using Java 1.7.