How to compare Active Directory last login date with current date in the system?
you can convert AD format date into a Date on this way:
long longDate = (Long.parseLong(adDate) / 10000L) - + 11644473600000L;
Date finalDate = new Date(longDate);
and later you can compare with a new Date()
@anubhav_varshney07
your Sailpoint timestamp is epoch actually , use below code to validate
/
/ Example AD ldapTimeStamp (100-nanosecond intervals since 1601-01-01)
long ldapTimestamp = 132456789012345678L; // replace with your ldapTimeStamp
// Convert AD ldapTimeStamp to milliseconds since Unix Epoch (1970-01-01)
long ldapEpochMillis = (ldapTimestamp / 10000L) - 11644473600000L;
// Example Unix timestamp (in seconds since 1970-01-01)
long unixTimestamp = 1698251234L; // replace with your Unix timestamp
// Convert Unix timestamp to milliseconds
long unixEpochMillis = unixTimestamp * 1000L;
// Compare both timestamps
if (ldapEpochMillis > unixEpochMillis) {
System.out.println("AD timestamp is later than Unix timestamp.");
} else if (ldapEpochMillis < unixEpochMillis) {
System.out.println("AD timestamp is earlier than Unix timestamp.");
} else {
System.out.println("AD timestamp is equal to Unix timestamp.");
}
or use below
long ldapTimestamp = 132456789012345678L; // replace with your ldapTimeStamp
// Convert LDAP timestamp to milliseconds since Unix Epoch (1970-01-01)
long epochMillis = (ldapTimestamp / 10000L) - 11644473600000L;
// Create a java.util.Date from the epoch milliseconds
Date ADDate = new Date(epochMillis);
now you can acually compare above ADDate with system date
1 Like
If it helps here you have a post in IdentityIQ Community Forum about this exactly:
Hope this helps!!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.