Skip to Content

How to convert AD accountexpires in Local timezone format

Hello Everyone,

In my current project IDM 7.2 SP10, we are reading accountexpires attribute from AD and then converting it to a readable format using uInt8ToDate function.

This function is converting the date in readable GMT format while client want it in local time. While searching SCN, I got below post which says that "True" switch is not working in uInt8ToDate function and even I observed the same.

Can anyone guide how can I convert the date in local timezone. I tried to use getTimezoneOffset() but it thrown error. Any help with the JavaScript formula will be appreciated.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 21, 2016 at 12:32 PM

    Hello C Kumar,

    I use this script to retrieve the accountExpires from AD and set it to the local validto attribute for AD:

    var MSTimestamp = Par;
    var MSTimestampNormalized = (MSTimestamp - 116444736000000000 - 864000000000) / 10000;
    var date = new Date(MSTimestampNormalized);
    var MonthValue = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
    var dayOfMonth = '' + date.getDate();
    if (dayOfMonth.length == 1) { dayOfMonth = "0" + dayOfMonth; }
    return date.getFullYear() + "-" + MonthValue[date.getMonth()] + "-" + dayOfMonth;

    Never thought of the time gap between GMT and CET though. I always take a day of (864000000000) due to the difference from accountExpires and validto.

    I guess I would have to add or subtract another milliseconds value to match up the different time zones we have (plants all around the world) if sdomeone actually would complain about a user being locked too early just because of the day hasn't passed yet. I guess the local Domain Controllers in every country handle the date correctly.

    If ever needed I would use a time zone difference in hours and store it on each company. Then I'd use this one in the script to add / subtract the amount of hours before calculating the new Date thingy.

    Best regards


    Add comment
    10|10000 characters needed characters exceeded

    • Hi Dominik,

      Can you please let me know how to convert the current date to LDAP/filetime, so that enddate can be passed to the AccountExpires attribute in AD



  • Apr 25, 2018 at 10:26 AM
      if (" ") > -1){
      Par = Par.split(" ")[0];
     // Add T00:00:00 if needed
     if ("T") == -1 ){
      Par += "T00:00:00";
     var splitted   = Par.split("T");
     // 1st part
     var splittedDate  = splitted[0];
     splittedDate    = splittedDate.split("-");
     var year    = splittedDate[0];
     var month    = splittedDate[1] - 1; // Minus 1 needed
     var day    = splittedDate[2];
     // 2nd part
     var splittedTime = splitted[1];
     splittedTime   = splittedTime.split(":");
     var hours    = splittedTime[0];
     var minutes   = splittedTime[1];
     var seconds   = splittedTime[2];
     // New date object
     var adDate   = Date.UTC(year, month, day, hours, minutes, seconds);
     adDate    = adDate * 10000 + 116444736000000000 + 864000000000; // Has to be this high!
     // Error handling
     if (adDate == "" || adDate == null || adDate.toString() == "NaN" || Par >= "9999-12-31"){
      adDate   = "9223372036854775807";
     return adDate;

    This should help. Parameter can be either formatted like "2018-04-25", "2018-04-25 12:15:00" or "2018-04-25T12:15:00" Please test if it fits your needs. Maybe the calculation of adDate has to be adapted, but it works for me

    Add comment
    10|10000 characters needed characters exceeded