gpt4 book ai didi

java - yyyy-MM-dd'T'HH :mm:ss. SSSZZ 和 yyyy-MM-dd'T'HH :mm:ss. SSSXXX 之间的区别?

转载 作者:行者123 更新时间:2023-12-02 01:17:09 27 4
gpt4 key购买 nike

想知道它们是否代表不同的格式或本质上相同(只是新与旧的演示文稿)。

最佳答案

基于DateTimeFormatter :

Offset X and x: This formats the offset based on the number of pattern letters.
-One letter outputs just the hour, such as '+01', unless the minute is non-zero in which case the minute is also output, such as '+0130'.
-Two letters outputs the hour and minute, without a colon, such as '+0130'.
-Three letters outputs the hour and minute, with a colon, such as '+01:30'.
-Four letters outputs the hour and minute and optional second, without a colon, such as '+013015'.
-Five letters outputs the hour and minute and optional second, with a colon, such as '+01:30:15'.
-Six or more letters throws IllegalArgumentException. Pattern letter 'X' (upper case) will output 'Z' when the offset to be output would be zero, whereas pattern letter 'x' (lower case) will output '+00', '+0000', or '+00:00'.

Offset Z: This formats the offset based on the number of pattern letters.
-One, two or three letters outputs the hour and minute, without a colon, such as '+0130'. The output will be '+0000' when the offset is zero.
-Four letters outputs the full form of localized offset, equivalent to four letters of Offset-O. The output will be the corresponding localized offset text if the offset is zero.
-Five letters outputs the hour, minute, with optional second if non-zero, with colon. It outputs 'Z' if the offset is zero.
-Six or more letters throws IllegalArgumentException.

代码:

public static void printDate(Temporal t, String format) {
System.out.println(DateTimeFormatter.ofPattern(format).format(t));
}

public static void testJavaTime() {
ZonedDateTime zdt = ZonedDateTime.now();
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSZ"); //2019-10-14 08:15:53.115+0200
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSZZ"); //2019-10-14 08:15:53.115+0200
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSZZZ"); //2019-10-14 08:15:53.115+0200
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSZZZZ"); //2019-10-14 08:15:53.115GMT+02:00
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSZZZZZ"); //2019-10-14 08:15:53.115+02:00
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSX"); //2019-10-14 08:15:53.115+02
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSXX"); //2019-10-14 08:15:53.115+0200
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSXXX"); //2019-10-14 08:15:53.115+02:00
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSXXXX"); //2019-10-14 08:15:53.115+0200
printDate(zdt, "yyyy-MM-dd HH:mm:ss.SSSXXXXX"); //2019-10-14 08:15:53.115+02:00
}
<小时/>

基于SimpleDateFormat ,这是一个简单的可能格式问题:

Z   Time zone   RFC 822 time zone   -0800
X Time zone ISO 8601 time zone -08; -0800; -08:00

无论Z的数量是多少,它总是使用[-+]####
格式但对于 X 来说,情况就不同了。

  • X : [-+]##
  • XX:[-+]####
  • XXX:[-+]##:##

现在,让我们演示一下:

public static void printDate(Date d, String format){
System.out.println(new SimpleDateFormat(format).format(d));
}

public static void testJavaDate() {
Date d = new Date();
printDate(d, "yyyy-MM-dd HH:mm:ss.SSSZ"); //2019-10-14 07:52:10.308+0200
printDate(d, "yyyy-MM-dd HH:mm:ss.SSSZZ"); //2019-10-14 07:52:10.308+0200
printDate(d, "yyyy-MM-dd HH:mm:ss.SSSZZZ"); //2019-10-14 07:52:10.308+0200
printDate(d, "yyyy-MM-dd HH:mm:ss.SSSX"); //2019-10-14 07:52:10.308+02
printDate(d, "yyyy-MM-dd HH:mm:ss.SSSXX"); //2019-10-14 07:52:10.308+0200
printDate(d, "yyyy-MM-dd HH:mm:ss.SSSXXX"); //2019-10-14 07:52:10.308+02:00
}

关于java - yyyy-MM-dd'T'HH :mm:ss. SSSZZ 和 yyyy-MM-dd'T'HH :mm:ss. SSSXXX 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58370435/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com