1

我遇到了 Sq-lite 数据库。我发现我们的日期时间存储在 18 位时间戳中。

请帮助我如何将其转换为当地时间。(我试图转换它(从 1900 年开始的毫秒数)。但我没有得到它。它显示了 29 天的差异。我添加了 29 天的毫秒时间。但时间输出是错误的。我的假设是,它将是NTP 时间。)

在这里,我给出了 18 位时间戳及其等效的日期时间。

时间戳日期时间

362087070028927400 27-10-2014 15:06:57
362087302762879170 27-10-2014 15:22:
22:22:
06 362087302763135170
27-10-2014 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

谢谢

4

4 回答 4

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。

于 2014-11-04T07:05:11.297 回答
1

这是我在 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。希望这是有道理的。这是额外的东西,但您可能需要它来转换有问题的列。

于 2019-11-06T22:23:36.437 回答
0

谢谢乔恩斯基特。

我试过没有 NodaTime dll。

我的代码在 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

现在我得到了正确的日期。

感谢您宝贵的回复和回答。

于 2014-11-04T07:46:48.587 回答
0

为 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;
于 2017-06-29T10:51:21.660 回答