Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to convert a large number of nanoseconds into a date ???

Bonjour,

 

I have "Account-Expires" attribute from Microsoft LDAP (using talend tLDAPinput component) : 

 

"The date when the account expires. This value represents the number of 100-nanosecond intervals since January 1, 1601 (UTC). A value of 0 or 0x7FFFFFFFFFFFFFFF (9223372036854775807) indicates that the account never expires."

 

It comes as a string.

 

Exemple : 130040605000000000 

 

I'd like to convert it into a date "dd/MM/yyyy" .

 

Any idea ?

 

I tried with TalendDate.addDate("01/01/1601", "dd/MM/yyyy",Var.var3 ,"ss") 

but Var.var3 has to be expressed as an integer ... 

the string express buckets of 100 nanoseconds ... a second is 10^9 nano second.

 

so 130040605000000000 represent

    13004060500 seconds since 01/01/1601 

 

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II

This value is too large an integer in Java.

It must be included between -2147483648 and 2147483647.

View solution in original post

6 Replies
TRF
Champion II

If 13004060500 is the number of seconds since 01/01/1601, (13004060500/3600/24) represents the number of days.
Then, TalendDate.addDate("01/01/1601", "yyyy/MM/dd", n, "dd") where n is the number of days should gives the result but not sure (not tested) it works for dates before 1970/01/01 as this is the base (epoch) for Java.
Anonymous
Not applicable
Author

Bonjour, 

 

Thank you for your answer. 

 

Yes 13004060500 is the number of seconds ... but I have difficulties to manipulate it as an integer ...

using parseInt is rejected.

 

I will continue to test.

 

Thank you for your contribution.

Anonymous
Not applicable
Author

using   Integer.parseInt("13235158809") 

 

java.lang.Exception: java.lang.NumberFormatException: For input string: "13235158809"

TRF
Champion II

This value is too large an integer in Java.

It must be included between -2147483648 and 2147483647.

Anonymous
Not applicable
Author

as the "dates" in Microsoft Active Directory are expressed in buckets of 100 nanoseconds, I've started to suppress the last 7 caracters of the string. The result is supposed to be in seconds. What I need is to have a date, some converting in days is dividing seconds by 60x60x24=86400 ... so I suppressed 2 additional caracters in the string. Then, parseint is possible.

 

row6.accountExpires == null || row6.accountExpires.equals("0") || row6.accountExpires.equals("9223372036854775807") ? "0" : StringHandling.LEFT(row6.accountExpires, StringHandling.LEN( row6.accountExpires )-9 )       ==> Var.accountExpires

 

Integer.parseInt(Var.accountExpires) / 864     ==> accountExpiresint

 

Var.accountExpiresint == 0 ? "0" : TalendDate.addDate("01.01.1601", "dd.MM.yyyy", Var.accountExpiresint , "dd")

 

Thank you for your support TRF.

TRF
Champion II

Thanks for sharing how you finaly solved your case.