转换time_t的蜱 [英] convert time_t to ticks
问题描述
我有一个转换蜱time_t的格式的功能。
I have a function that convert ticks to time_t format
long ticks = DateTime.Now.Ticks;
long tt = GetTimeTSecondsFrom(ticks);
long GetTimeTSecondsFrom(long ticks)
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return (long) (new DateTime(ticks) - epoch).TotalSeconds;
}
现在我很困惑如何将它与一些数学公式转换回蜱不能用的功能。
Now i am confused how to convert it back to ticks with some mathematical formula and not with a function.
任何建议... ??
Any suggestions...??
感谢
让我来一般情况,并解释。
DateTime.Now.Ticks给我一个值633921719670980000这是在抽动
Let me take a general case and explain. DateTime.Now.Ticks give me a value 633921719670980000 which is in tics
然后我转换这time_t的上述功能,让TT = 1256575167
then i convert this in time_t with the above function and get tt = 1256575167
现在我想这个转换回633921719670980000.为了这个,我需要一个公式
now i want to convert this back to 633921719670980000. for this i need a formula
推荐答案
日期 1970-01-01 00:00:00ž
正是62135596800秒(621,355,968,000,000,000蜱),所以要转换的DateTime
滴答计数成 time_t的
价值,你可能只是它的规模(由10,000,000分),以获得秒钟,然后再减去偏移量。
The date1970-01-01 00:00:00 Z
is exactly 62,135,596,800 seconds (621,355,968,000,000,000 ticks), so to convert aDateTime
tick count into atime_t
value you could just scale it (divide by 10,000,000) to get seconds, and then subtract that offset.
要走另一条路,做相反:偏移秒添加到 time_t的
值,然后将10,000,000缩放(乘),以获得蜱。
To go the other way, do the reverse: add the offset seconds to thetime_t
value, then scale it (multiply by 10,000,000) to get ticks.
这篇关于转换time_t的蜱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!