I had to consume an XML data that contains .NET DateTime Ticks (long type) value. This should do it.
import java.util.*;
public class DotNetTicksUtil
{
private static final long TICKS_AT_EPOCH = 621355968000000000L;
private static final long TICKS_PER_MILLISECOND = 10000;
/**
* Given a .NET ticks value, we convert it to Java's Calendar object.
* Conversion may not be perfectly precise, so do expect some margin of errors.
*/
public static Calendar toCalender(long ticks)
{
//long ticks = 634200192000000000L;
Date date = new Date((ticks - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND);
System.out.println(date);
TimeZone utc = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(utc);
calendar.setTime(date);
return calendar;
}
}
0 件のコメント:
コメントを投稿