Udo Held Udo Held - 6 months ago 148
Java Question

Converting a ldap date

I'm exporting users from an ldap programmatically. Therefor I'm retrieving the users from ldap. One of the attributes is


One of the values I have to convert is:
Directly splitting it up I get the following format:
. The problem is that the application is running in CET timezone and the time stored is UTC which is probably indicated by the
. It is
14:56 UTC
and the local representation is
. For summer time it seems to be 2 hours and for winter time 1 hour.

I checked the SimpleDateFormat and there is a placeholder for the timezone, however its a different format.

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

Will show the wrong date as it ignores the dates time zone.

Is there a way to convert it directly?


What about using the split you described above, then reformatting the 0Z timezone into a standard format, then using sdf.parse(...)? Maybe something like this (with appropriate error checking added, of course):

String[] parts = inputDateTime.split("[.]");
String dateTimePart = parts[0];
String timeZonePart = "+0" + parts[1].substring(0, parts[1].length() - 1) + "00";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssZ");
Date theDate = sdf.parse(dateTimePart + timeZonePart);