0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NTタイムエポック-.NET DateTime変換

Last updated at Posted at 2020-09-09

NTタイムエポック値 = (.NET Ticks値) - 504911232000000000

Console
# 1601/1/1 00:00:00の時点のTicks
PS> ([DateTime]"1601/1/1 00:00:00").Ticks
504911232000000000

Ticks(100ナノ秒のカウント)

.NETは「1/1/1 00:00:00」からTicksが計上されます。
Windows NTエポックは「1601/1/1 00:00:00」からTicksが計上されます。

差分のTicks「504911232000000000」を追加して計算します。

※ちなみにExcelは、「1899/12/31 00:00:00」から1hourで計上され、
分以下は小数点で処理をすることとなり、誤差も発生します。

test.ps1
[System.Int64]$NT_TimeEpoc = 132441743819134704 #取得したActiveDirectory上のTicks
$Time = [System.DateTime]::new($NT_TimeEpoc + 504911232000000000)

PowershellバージョンによってはDateTimeを以下の宣言で

test.ps1
[System.Int64]$NT_TimeEpoc = 132441743819134704 #取得したActiveDirectory上のTicks
$Time = New-Object System.DateTime($NT_TimeEpoc + 504911232000000000)

UTC>JST(9:00)の差分追加

test.ps1
[System.Int64]$NT_TimeEpoc = 132441743819134704 #取得したActiveDirectory上のTicks
$Time = New-Object System.DateTime($NT_TimeEpoc + 504911232000000000 + 324000000000)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?