将Java日期转换为18 dgit LDAP日期 [英] Convert java date to 18 dgit LDAP date

查看:108
本文介绍了将Java日期转换为18 dgit LDAP日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一项要求,我们需要在Active Directory中插入accountExpires日期. 并且AD仅将输入日期作为大整数(18位LDAP日期). 我有一个格式为yyyy-MM-dd的日期(例如:2014-04-29),并且我想将此Java日期转换为LDAP日期18位数字格式,即(130432824000000000).

We have a requirment where we need to insert accountExpires date in Active directory. And AD only take input date as Large integer (18 digit LDAP date). I have a date in format yyyy-MM-dd (for ex : 2014-04-29) and I want to convert this Java date into LDAP date 18 digit format i.e (130432824000000000).

请让我知道可以转换以下格式并使用当前日期格式填充广告的任何方法.

Please let me know any work around to convert the below format and populate the AD with curre nt date format.

推荐答案

根据找到的定义,这是使用Joda Time的解决方案

This is a solution using Joda Time, according to the definition found here:

时间戳记是自1601年UTC以来的100纳秒间隔(1纳秒=十亿分之一秒)的数量.

The timestamp is the number of 100-nanoseconds intervals (1 nanosecond = one billionth of a second) since Jan 1, 1601 UTC.

示例代码:

public final class Foo
{
    private static final DateTime LDAP_START_DATE
        = new DateTime(1601, 1, 1, 0, 0, DateTimeZone.UTC);

    public static void main(final String... args)
    {
        final DateTime now = DateTime.now();
        final Interval interval = new Interval(LDAP_START_DATE, now);
        System.out.println(interval.toDurationMillis() * 10000);
    }
}

将此代码中的now替换为您的日期,并且应该被设置.

Replace now in this code with your date and you should be set.

这篇关于将Java日期转换为18 dgit LDAP日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆