|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729281
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2022/11/1 9:35 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [轉貼]Timestamp from LDAP
- Timestamp from LDAP (ActiveDirectories lastLogonTimestamp)
Question
If I get a Timestamp it's ms since Epoch 1143584229619
But in LDAP I get a value from the timestamp more like 127877417297554938
First though was maybe ms since time of '01/01/0000' or something but it does not add up that way.
Does anyone know what the timestamp maybe; and how I can convert it into something Java can use.
Thanks in advance.
--------------------------------------------------------------------------------
Answers
Hi
lastLogonTimeStamp seems to be the no of 100 nano second intervals starting from 0000 hrs 1/1/1601.
This is similiar to windows file time format and .NET has support to create a System.DateTime object out of this value.. Note the sample here, using the long value that you had provided and watch the date being recreated..
.NET Sample :
import System.*;
class Test
{
public static void main(String args[])
{
DateTime dt=DateTime.FromFileTime(127877417297554938L);
System.out.println(dt);
}
}
Java Sample :
If you want to create a java date object out of this value, please try following this sample, where i have used an adjustment factor to convert the lastLogonTimestamp value into a Date object..
import java.util.*;
class Test
{
public static void main(String args[])
{
long llastLogonAdjust=11644473600000L; // adjust factor for converting it to java
//date Epoch
Date lastLogon = new Date(127877417297554938L/10000-llastLogonAdjust); //
System.out.println(lastLogon);
}
}
Thanks
--------------------------------------------------------------------------------
All replies
Hi
lastLogonTimeStamp seems to be the no of 100 nano second intervals starting from 0000 hrs 1/1/1601.
This is similiar to windows file time format and .NET has support to create a System.DateTime object out of this value.. Note the sample here, using the long value that you had provided and watch the date being recreated..
.NET Sample :
import System.*;
class Test
{
public static void main(String args[])
{
DateTime dt=DateTime.FromFileTime(127877417297554938L);
System.out.println(dt);
}
}
Java Sample :
If you want to create a java date object out of this value, please try following this sample, where i have used an adjustment factor to convert the lastLogonTimestamp value into a Date object..
import java.util.*;
class Test
{
public static void main(String args[])
{
long llastLogonAdjust=11644473600000L; // adjust factor for converting it to java
//date Epoch
Date lastLogon = new Date(127877417297554938L/10000-llastLogonAdjust); //
System.out.println(lastLogon);
}
}
Thanks
原文出處:Timestamp from LDAP (ActiveDirectories lastLogonTimestamp)
冷日: 簡言之,就是 Windows AD 的時間不是 UnixTimestamp! 所以有一個誤差值:11644473600000L
以下是Java Ldap convert lastLogonTimestamp to DateTime - Stack Overflow提供的解答: To convert a Win32 filetime string to Date, use:
long fileTime = (Long.parseLong(inputDateString) / 10000L) -
11644473600000L;
Date inputDate = new Date(fileTime);
To convert a Date to Win32 filetime, use:
long fileTime = (inputDate.getTime() + 11644473600000L) * 10000L;
String outputDate = Long.toString(fileTime);
e.g. 131220409910000000 will be converted to 2016/10/27 14-23-11 and vice versa
Check this url for a nice online epoch/filetime converter:http://www.epochconverter.com/ldap
|
|
|
討論串
|