ISO 8601中的时间戳-后6位yyyy-MM-dd'T'HH:mm:ss. [英] Timestamp in ISO 8601 - the last 6 digits yyyy-MM-dd'T'HH:mm:ss.?

查看:139
本文介绍了ISO 8601中的时间戳-后6位yyyy-MM-dd'T'HH:mm:ss.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的时间戳:

    2015-03-21T11:08:14.859831
    2015-03-21T11:07:22.956087

我阅读了有关ISO 8601的Wiki文章,但没有得到最后6位数字.

I read a Wiki article on ISO 8601, but did not get the meaning of the last 6 digits here.

我尝试使用"yyyy-MM-dd'T'HH:mm:ss.sss" "yyyy-MM-dd'T'HHmm:ss.ssssss".是不是比毫秒更精确-高达微秒?

I tried getting it down to milliseconds using "yyyy-MM-dd'T'HH:mm:ss.sss" or "yyyy-MM-dd'T'HH:mm:ss.ssssss". Is it just more precise than milliseconds - up to microseconds?

推荐答案

它比毫秒更精确吗?

Is it just more precise than milliseconds?

是的,在这种情况下是微秒.

Yes, it's microseconds in this case.

ISO-8601实际上没有指定最大精度.它指出:

ISO-8601 doesn't actually specify a maximum precision. It states:

如果对于特定的应用程序是必需的,则可以包括小时,分钟或秒的小数部分.如果包括小数部分,则应省略低阶时间元素(如果有),并且小数部分应从整数部分除以ISO 31-0中指定的小数点,即逗号[,]或句号[.].其中,逗号是首选符号.如果数字的大小小于1,则按照3.6的规定,小数点后应有两个零.

If necessary for a particular application a decimal fraction of hour, minute or second may be included. If a decimal fraction is included, lower order time elements (if any) shall be omitted and the decimal fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0, i.e. the comma [,] or full stop [.]. Of these, the comma is the preferred sign. If the magnitude of the number is less than unity, the decimal sign shall be preceded by two zeros in accordance with 3.6.

根据应用程序,交换双方应同意小数点后的位数.[...]

The interchange parties, dependent upon the application, shall agree the number of digits in the decimal fraction. [...]

(实际上,您很少 将逗号作为小数点分隔符-至少这是我的经验.)

(You very rarely actually see comma as the decimal separator - at least, that's my experience.)

不幸的是,根据我的经验,在Java 7中解析这样的值是很棘手的-没有用于只消耗小数位并做正确的事情"的格式说明符.您可能会发现需要先将尾随的3位数字切掉,然后才能以毫秒为单位进行解析.

Unfortunately in my experience, parsing a value like this in Java 7 is tricky - there isn't a format specifier for "just consume fractional digits and do the right thing". You may find you need to manually chop the trailing 3 digits off before parsing as milliseconds.

由于Java 8支持纳秒级的精度,因此相当简单-实际上,内置的ISO格式化程序可以很好地对其进行解析:

As Java 8 supports a precision of nanoseconds, it's rather simpler - and in fact, the built-in ISO formatter can parse it fine:

import java.time.*;
import java.time.format.*;

public class Test {
    public static void main(String[] args) {
        DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
        System.out.println(LocalDateTime.parse("2015-03-21T11:07:22.956087", formatter));
        
    }
}

这篇关于ISO 8601中的时间戳-后6位yyyy-MM-dd'T'HH:mm:ss.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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