开发者

convert ticks to time_t or Filetime()

开发者 https://www.devze.com 2022-12-09 01:41 出处:网络
How do开发者_如何转开发 I convert ticks to time_t or filetime()?time_t is defined as the number of seconds from the Unix epoch date January 1, 1970 @ 00:00 UTC.So, you basically need to figure out how

How do开发者_如何转开发 I convert ticks to time_t or filetime()?


time_t is defined as the number of seconds from the Unix epoch date January 1, 1970 @ 00:00 UTC. So, you basically need to figure out how much time your ticks represent and subtract the epoch time. The following should do it.

double GetTimeTSecondsFrom(long ticks)
{
    DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    return (new DateTime(ticks) - epoch).TotalSeconds;
}


For time_t:

long ticks =  633918528000000000;
DateTime target = new DateTime(ticks);
DateTime start = new DateTime(1970, 1, 1, 0, 0, 0);
double time_t = (target - start).TotalSeconds;
0

精彩评论

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

关注公众号