我遇到了Sq-lite数据库。我发现我们的日期时间存储在18位数的时间戳中。
请帮我解释如何将其转换为本地时间。 (我试图转换它(从1900开始的毫秒数)。但是我没有得到它。它显示了29天的差异。我加了29天毫秒的时间。但时间输出是错误的。我的假设是,它将是NTP时间。)
这里我给出18位数的时间戳及其等效的日期时间。
362087070028927400 27-10-2014 15:06:57
362087302762879170 27-10-2014 15:22:06
362087302763135170 27-10-2014 15:22:06
362087302851460030 27-10-2014 15:22:06
362087302851716030 27-10-2014 15:22:06
362087302851716030 27-10-2014 15:22:06
362087305419799000 27-10-2014 15:22:16
362087307972777150 27-10-2014 15:22:26
362087310530875300 27-10-2014 15:22:36
362087313092045760 27-10-2014 15:22:46
362087315652448200 27-10-2014 15:22:56
362087318210802600 27-10-2014 15:23:06
362087320772741060 27-10-2014 15:23:16
362087323333655740 27-10-2014 15:23:26
由于
答案 0 :(得分:1)
在我看来,它基于1970年(Unix时代),而不是1900年,每秒有256000000“滴答”。
我之前没有见过这样的格式,但似乎要检查 - 例如,使用Noda Time:
using System;
using NodaTime;
class Test
{
static void Main()
{
Console.WriteLine(ToInstant(362087323333655740));
}
static Instant ToInstant(long value)
{
// We don't have to truncate to milliseconds, but it's simple for now...
long millis = value / 256000;
return Instant.FromMillisecondsSinceUnixEpoch(millis);
}
}
输出:
2014-10-27T09:53:26Z
......这对应于2014-10-27T15:23:26作为印度当地时间。
答案 1 :(得分:0)
感谢Jon Skeet。
我试过没有NodaTime dll。
我的代码为In Vb.net;
Dim theDate As Date = New Date(1970, 1, 1, 0, 0, 0).AddMilliseconds(CLng(lstUnixTime.Items(k) / 256000L))
Dim offsetAmount As TimeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(New Date(1900, 1, 1, 0, 0, 0))
theDate += offsetAmount
现在我得到正确的约会。
感谢您的宝贵回复和答复。
答案 2 :(得分:0)
for php
$dateLargeInt= "131424999530821857";
$secsAfterADEpoch = $dateLargeInt / (10000000);
$ADToUnixConvertor=((1970-1601) * 365.242190) * 86400;
// unix epoch - AD epoch * number of tropical days * seconds in a day
$unixTsLastLogon=intval($secsAfterADEpoch-$ADToUnixConvertor);
// unix Timestamp version of AD timestamp
$lastlogon=date("d-m-Y", $unixTsLastLogon); // formatted date
echo $lastlogon;
答案 3 :(得分:0)
这是我在Python中完成的一个解决方案,对我来说效果很好(这适用于18位LDAP / Active Directory时间戳记):
import datetime
def ad_timestamp(timestamp):
if timestamp != 0:
return datetime.datetime(1601, 1, 1) + datetime.timedelta(seconds=timestamp/10000000)
return np.nan
因此,如果您需要转换Pandas列:
df.lastLogonTimestamp = df.lastLogonTimestamp.fillna(0).apply(ad_timestamp)
注意:我需要先使用fillna
,然后再使用apply
。另外,由于我填充了0,因此我在转换函数if timestamp != 0
中进行了检查。希望有道理。这是多余的东西,但您可能需要用它来转换有关的列。