开发者

Android: TimeStamp conversion question!

I'm parsing some xml for tv guide data and ran into开发者_如何学运维 this 18 digit timestamp (633934980000869533). Looks like C#'s DateTime ticks. Does anyone know how to convert this to regular java Date/Time?


If it is a .NET ticks value, you've just got to scale and rebase it.

Midnight on January 1st 1970 is represented by 621355968000000000 ticks in .NET, and 1 millisecond = 10,000 ticks... so:

public static Date fromDotNetTicks(long ticks)
{
    // Rebase to Jan 1st 1970, the Unix epoch
    ticks -= 621355968000000000L;
    long millis = ticks / 10000;
    return new Date(millis);
}

Obviously you'll probably want to extract those magic numbers into named constants :)

I've just checked, and the code above gives November 11th 2009, 1am UTC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜