I'm retrieving a group of objects from eDirectory...
Articles and Tips: qna
01 Aug 2002
Q.
I'm retrieving a group of objects from eDirectory using the SearchLdapEntries bean and the SortControl and VirtualListViewControl controls. Some attributes have the 'Time' syntax and I'm trying to format them using DateFormat, but it is not working. When I read the attribute from ConsoleOne I can read the date as "Fri Jun 1417:01:37 EDT 2002" but the attribute in my Java code has the value "20020614210137Z."Any ideas?
A.
Below is some code that should help:
/** * CompareTime() parses UTCTime into locale Date, and then * compare it with system Date. * @param UTCTime as stored in Server * @return boolean True if UTCTime is after system time. * @throws ParseException - when errors occur. */ public static boolean CompareTime( String UTCTime ) { Date date = null, currentDate = new Date(); // setup x.208 generalized time formatter DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); //DateFormat fm = DateFormat.getDateInstance(Locale.GMT); // all time in UTC - must set formatter TimeZone tz = TimeZone.getTimeZone("UTC"); formatter.setTimeZone(tz); try { // parse into Date - converted to locale time zone date = formatter.parse( UTCTime ); } catch(ParseException pe) { System.out.println( "\n [CompareTime] Error: " + pe.toString() ); } return date.after(currentDate); }
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.