Novell Home

Converting AD Password Attribute from UTC to a Java Timestamp

Novell Cool Solutions: Tip
By Scott Kraemer

Digg This - Slashdot This

Posted: 27 Sep 2006
 

Problem

I needed to convert the AD Attribute pwdLastSet from UTC time to a Java/SQL/DB2 format such as this: 20060425205130Z

I looked at the jadutils transformEpoch2FileTime and FileTimetoEpoch, but they don't do what I want.

Solution

I created my own Java class to convert it:

/*
 * Utilities.java
 *
 * Created on September 14, 2006, 12:32 PM
 */

package com.acme.util;

import java.util.*;
import java.text.*;

/**
 *
 * @author  e144717
 */
public class Utilities {
    
    /** Creates a new instance of Utilities */
    public Utilities() {
    }
     
public static String fileTime2timestamp(String s)
{
     long pwdSetDate = java.lang.Long.parseLong(s);
     long timeAdjust=11644473600000L;  // adjust factor for converting it 
to java    
     Date pwdSet = new Date(pwdSetDate/10000-timeAdjust); // 
     DateFormat mydate = new SimpleDateFormat("yyyyMMddHHmmss");
     return(mydate.format(pwdSet));
}
}


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell