目前我已经尝试过这段代码,但问题是第一行代码给出了这个输出20150217172651 + 0100而且我要求的输出是20150217172651.0Z
GeneralizedTime gt = new GeneralizedTime(Calendar.getInstance());
String gtADString = gt.toGeneralizedTime(
GeneralizedTime.Format.YEAR_MONTH_DAY_HOUR_MIN_SEC,
GeneralizedTime.FractionDelimiter.DOT, 1,
GeneralizedTime.TimeZoneFormat.Z).replaceFirst("Z", "\\.0Z");
答案 0 :(得分:0)
让你的代码
public class poc {
public static void main(String[] args) {
GeneralizedTime gt = new GeneralizedTime(Calendar.getInstance());
String gtADString = gt.toGeneralizedTime(
GeneralizedTime.Format.YEAR_MONTH_DAY_HOUR_MIN_SEC,
GeneralizedTime.FractionDelimiter.DOT, 1,
GeneralizedTime.TimeZoneFormat.Z).replaceFirst("Z", "\\.0Z");
System.out.println(gtADString);
}
}
并将此作为输出:
20150217163832.0Z
使用以下依赖项:
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-util</artifactId>
<version>1.0.0-M28</version>
</dependency>`
答案 1 :(得分:0)
您可以尝试如下:
long t1 = calenderObj.getTimeInMillis();
calenderObj.set(1601, 0, 1);
long t2 = calenderObj.getTimeInMillis();
long ldap = (t1 - t2) * 10000;
希望这会有所帮助。