这是什么时间戳格式



我一直在想这是什么时间戳:

2021-01-06T11:00:00.459907-07:00

特别是.459907,我一直在网上找,但一直找不到。

ISO 8601

格式为国际标准ISO 8601。长篇故事在底部的链接中。

CCD_ 2是秒的分数。另一种描述方式是,时间是上午11点之后的459907微秒(百万分之一秒(。在一天中的时间部分之前的固定字母T(我想是时间(是ISO 8601的特征。

您的字符串还包括一个日期,2021年1月6日,以及与UTC的偏移量减7小时00分钟。例如,在每年的这个时候,美国/埃德蒙顿和美国/丹佛时区(山地时间(都会使用这种偏移。偏移量-07:00表示时间比UTC晚7小时。因此,相应的UTC时间为18:00:00.459907。

链接

维基百科文章:ISO 8601

在另一个答案中,Ole V.V.已经描述了这个日期-时间字符串的格式。这个答案补充了他的答案。

大多数语言都有库来直接/间接解析这种日期-时间字符串。例如,在Java中,您可以将此字符串解析为OffsetDateTime,从而从中检索单个信息。

演示:

import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoField;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
OffsetDateTime odt = OffsetDateTime.parse("2021-01-06T11:00:00.459907-07:00");
long nanos = odt.getNano();
System.out.println(odt + " has " + nanos + " nanoseconds");
System.out.println(odt + " has " + odt.get(ChronoField.MICRO_OF_SECOND) + " microseconds");
System.out.println(odt + " has " + odt.get(ChronoField.MILLI_OF_SECOND) + " milliseconds");
System.out.println(nanos + " nanoseconds = " + TimeUnit.NANOSECONDS.toMicros(nanos) + " microseconds");
System.out.println(nanos + " nanoseconds = " + TimeUnit.NANOSECONDS.toMillis(nanos) + " milliseconds");
System.out.println(odt + " has a zone-offset of " + odt.getOffset() + " from UTC");
System.out.println("Month: " + odt.getMonth());
System.out.println("Day of month: " + odt.getDayOfMonth());
System.out.println("Weekday name: " + odt.getDayOfWeek());
System.out.println("Week of the year: " + odt.get(ChronoField.ALIGNED_WEEK_OF_YEAR));
System.out
.println("In terms of UTC, " + odt + " can be represented as " + odt.atZoneSameInstant(ZoneOffset.UTC));
OffsetDateTime odtWithNextCompleteSecond = OffsetDateTime.parse("2021-01-06T11:00:01-07:00");
System.out.println("After " + Duration.between(odt, odtWithNextCompleteSecond).toNanos()
+ " nanoseconds, this time will change to " + odtWithNextCompleteSecond);
}
}

输出:

2021-01-06T11:00:00.459907-07:00 has 459907000 nanoseconds
2021-01-06T11:00:00.459907-07:00 has 459907 microseconds
2021-01-06T11:00:00.459907-07:00 has 459 milliseconds
459907000 nanoseconds = 459907 microseconds
459907000 nanoseconds = 459 milliseconds
2021-01-06T11:00:00.459907-07:00 has a zone-offset of -07:00 from UTC
Month: JANUARY
Day of month: 6
Weekday name: WEDNESDAY
Week of the year: 1
In terms of UTC, 2021-01-06T11:00:00.459907-07:00 can be represented as 2021-01-06T18:00:00.459907Z
After 540093000 nanoseconds, this time will change to 2021-01-06T11:00:01-07:00

任何具有Java工作知识的人都可以从跟踪:日期时间了解API的日期时间。

最新更新