Format Ldap Date
Converts an LDAP timestamp (in the format “yyyyMMddHHmmssZ”) to a human-readable date and time string.
- Removes the “.0” suffix if present, keeping the “Z” timezone indicator.
- Parses the cleaned LDAP date string as UTC and converts it to a local time zone-aware format.
- Useful for displaying LDAP date attributes (e.g., “whenCreated”, “whenChanged”) in a user-friendly way.
VB
Public Function FormatLdapDate(RawDate As String) As String
' Remove ".0", keep "Z"
RawDate = RawDate.Replace(".0", "")
' Now the format is "yyyyMMddHHmmssZ"
Dim format As String = "yyyyMMddHHmmss'Z'"
Dim parsedDate As DateTimeOffset =
DateTimeOffset.ParseExact(RawDate, format,
System.Globalization.CultureInfo.InvariantCulture)
Return parsedDate.ToString("dd/MM/yyyy HH:mm:ss zzz")
End Function