Does anyone know an easy way to convert an AD attribute like
"pwdLastChanged" that is in Milliseconds from 1601 to a usable
Timestamp for ADAM. Is there an easy way to convert in TDI? I have
tried messing round with the "Date" Java util but cant seem to get
this one to work. I know there is a Windows app that can do it but was
hopping to do the conversion in TDI itself.
Anyone successfully done this?
Cheers
Crul
I do not have an ADAM to test with, so please let
me know what I am missing.
-Eddie
-Eddie
Thanks for looking at this,
I Still can’t quite get it right. I want to convert the PwdLastSet
attribute which is in format: "129144606760737926" and change it to a
Timestamp format like 20100413100455.0z
If I try:
changed.getObject("pwdLastChanged");
changeDate = new java.util.Date(changed);
I get an error:
java.lang.reflect.InvocationTargetException
Cused by:
java.lang.IllegalArgumentException
at java.util.Date.parse(Date.java:610)
at java.util.Date.<init>(Date.java:270)
... 27 more
so trying the following code
In the Output Map
-------------------------------------------
var msecss = work.getString("PwdLastSet");
task.logmsg("PwdLastSet : "+msecss);
var msecsd = new Date(msecss);
task.logmsg("New Date : "+msecsd);
times = new java.sql.Timestamp(msecsd.getTime());
task.logmsg("Timestamp : "+times);
var er = system.remove("-",times);
var ty = system.remove(" ",er);
var ed = system.remove(":",ty);
var fed = ed.substring(0,8);
var fee = ed.substring(8,15);
var ts = (fed + fee +"0Z");
task.logmsg("Converted TS : "+ts);
ret.value = ts;
This is what I’m getting in my logs :
6:27:51 PwdLastSet : 129144585766593641
16:27:51 New Date : 1/01/70 12:00
16:27:51 Timestamp : 1970-01-01 12:00:00.0
16:27:51 Converted TS : 19700101120000.0Z
----------------------------------------------
It seems that the line 'var msecsd = new Date(msecss);' is just
returning 1/01/70 12:00 rather than a converted date for
129144585766593641.
Also it seems Java uses 1/01/70 12:00 as its Epoch where as AD looks
like it uses 1/01/1601 12:00. Is this going to cause me an issue?
All I really want to do is convert a number which is in Milliseconds
since 1601 format and put it into a regular timestamp format for ADAM.
Sorry if I explained this poorly but It really has me stumped, but I
am guessing others would have attempted this before with TDI.
Many Thanks
Crul
dt = changed.getObject("pwdLastChanged");
task.logmsg("Class is: " + dt.getClass());
You will need to convert to an integer in order to
create a date based on it. Same goes for the other
code snippet where you do a getString("PwdLastSet").
Make an int value out of it first and see if that helps.
As far as the different epochs, that just means you
create a diff value that you can add to the AD one to
get the corresponding Java version. In your case you'll
need to add msecs to the AD time value to get the
Unix epoch you need for Java date functions.
-Eddie
---
// Create a Win 32 "Year 0" date
Win32Epoch = new
java.util.GregorianCalendar(1601,java.util.Calendar.JANUARY,1);
// Get the java.util.Date object
Win32EpochDate = Win32Epoch.getTime()
// Get the msecs from the Date
Win32EpochMSecs = Win32EpochDate.getTime();
// Now do the same for Java Epoch
JavaEpochDate = new java.util.Date();
JavaEpochMSecs = JavaEpochDate.getTime();
EpochDiff = Win32EpochMSecs - JavaEpochMSecs;
task.logmsg("-EpochDiff-: "+EpochDiff);
// Note that "var" is really only for documentation
// purposes - except in function bodies. All variables
// are otherwise global
var msecss = work.getString("PwdLastSet");
task.logmsg("PwdLastSet (msecs): "+msecss);
msecsi = new java.lang.Long(msecss);
task.logmsg(" msecsi : " + msecsi);
AdjustedMsecs = msecsi - EpochDiff;
pwdLastSetDate = new java.util.Date(AdjustedMsecs);
task.logmsg( " PwdLastSet (date): " + pwdLastSetDate);
---
This date looked right for my system.
Hope it helps!
-Eddie
Yeah its quite an involved process.
I tried the following code:
// Create a Win 32 "Year 0" date
Win32Epoch = new
java.util.GregorianCalendar(1601,java.util.Calendar.JANUARY,1);
// Get the java.util.Date object
Win32EpochDate = Win32Epoch.getTime()
// Get the msecs from the Date
Win32EpochMSecs = Win32EpochDate.getTime();
// Now do the same for Java Epoch
JavaEpochDate = new java.util.Date();
JavaEpochMSecs = JavaEpochDate.getTime();
EpochDiff = Win32EpochMSecs - JavaEpochMSecs;
task.logmsg("-EpochDiff-: "+EpochDiff);
// Note that "var" is really only for documentation
// purposes - except in function bodies. All variables
// are otherwise global
var msecss = work.getString("PwdLastSet");
task.logmsg("PwdLastSet (msecs): "+msecss);
msecsi = new java.lang.Long(msecss);
task.logmsg(" msecsi : " + msecsi);
AdjustedMsecs = msecsi - EpochDiff;
pwdLastSetDate = new java.util.Date(AdjustedMsecs);
task.logmsg( " PwdLastSet (date): " + pwdLastSetDate);
time = new java.sql.Timestamp(pwdLastSetDate.getTime());
task.logmsg("Timestamp : "+time);
var er = system.remove("-",time);
var ty = system.remove(" ",er);
var ed = system.remove(":",ty);
var fed = ed.substring(0,8);
var fee = ed.substring(8,15);
var ts = (fed + fee +"0Z");
task.logmsg("Converted TS : "+ts);
I see how its all working together but my result I get is:
21:49:46 Timestamp : 4094972-01-19 00:12:12.352
21:49:46 Converted TS : 4094972011900120Z
The actual conversion comes to something like this:
21:08:51.8545664 - 6/04/2010 9:08:51 a.m.
I c;ant see which line I am doing wrong.
Sorry to be a pain but this one goes over my head a bit :P
Thanks again Eddie
Crul
But its returning 409497201190012.0Z a date a looong way in the
future
I cant see where I'm going wrong.
Cheers
---
s = work.getString("PwdLastSet");
pwdSetDate = new java.lang.Long.parseLong(s);
// adjust factor for converting it to java
timeAdjust= new java.lang.Long(11644473600000);
convdate = new java.lang.Long(pwdSetDate/10000-timeAdjust);
pwdSet = new java.util.Date(convDate);
---
See if this works any better. The whole trick here is
to get the right epoch diff when doing the conversion.
-Eddie