我有一个c#函数,需要从python发布者生成的epoch参数的秒数(以微秒为单位):
buffer.setTimestamp(calendar.timegm(time.gmtime())*1000*1000)
c#功能:
public static DateTime datetimeFromEpochTime(ulong timestamp)
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
DateTime ts = epoch.AddMilliseconds(timestamp / 1000);
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
return TimeZoneInfo.ConvertTimeFromUtc(ts, cstZone);
}
然而,返回的时间戳似乎提前了5个小时(我在CST)。例如,如果我输入1438004994000000
,则时间戳变为7/27/2015 1:49:54 PM
,但它应为7/27/2015 8:49:54 AM