这个日期格式是什么? 2011-08-12T20:17:46.384Z
本文翻译自:What is this date format? 2011-08-12T20:17:46.384Z
I have the following date: 2011-08-12T20:17:46.384Z
. 我有以下日期: 2011-08-12T20:17:46.384Z
。 What format is this? 这是什么格式? I'm trying to parse it with Java 1.4 via DateFormat.getDateInstance().parse(dateStr)
and I'm getting 我试图通过DateFormat.getDateInstance().parse(dateStr)
用Java 1.4解析它,
java.text.ParseException: Unparseable date: "2011-08-12T20:17:46.384Z" java.text.ParseException:无法解析的日期:“ 2011-08-12T20:17:46.384Z”
I think I should be using SimpleDateFormat for parsing, but I have to know the format string first. 我想我应该使用SimpleDateFormat进行解析,但是我必须首先知道格式字符串。 All I have for that so far is yyyy-MM-dd
, because I don't know what the T
means in this string--something time zone-related? 到目前为止,我所拥有的只是yyyy-MM-dd
,因为我不知道T
在此字符串中的含义是什么-与时区有关? This date string is coming from the lcmis:downloadedOn
tag shown on Files CMIS download history media type . 此日期字符串来自文件CMIS下载历史记录媒体类型上显示的lcmis:downloadedOn
标记。
#1楼
参考:https://stackoom.com/question/ZGXv/这个日期格式是什么-T-Z
#2楼
tl;dr tl; dr
Standard ISO 8601 format is used by your input string. 输入字符串使用标准ISO 8601格式。
Instant.parse ( "2011-08-12T20:17:46.384Z" )
ISO 8601 ISO 8601
This format is defined by the sensible practical standard, ISO 8601 . 此格式由明智的实用标准ISO 8601定义 。
The T
separates the date portion from the time-of-day portion. T
将日期部分与时间部分分开。 The Z
on the end means UTC (that is, an offset-from-UTC of zero hours-minutes-seconds). 末尾的Z
表示UTC (即,相对于UTC的偏移量为零小时-分钟-秒)。 The Z
is pronounced “Zulu” . Z
发音为“ Zulu” 。
java.time java.time
The old date-time classes bundled with the earliest versions of Java have proven to be poorly designed, confusing, and troublesome. 事实证明,与最早的Java版本捆绑在一起的旧的日期时间类设计不佳,令人困惑且麻烦。 Avoid them. 避免他们。
Instead, use the java.time framework built into Java 8 and later. 相反,请使用Java 8及更高版本中内置的java.time框架。 The java.time classes supplant both the old date-time classes and the highly successful Joda-Time library. java.time类取代了旧的日期时间类和非常成功的Joda-Time库。
The java.time classes use ISO 8601 by default when parsing/generating textual representations of date-time values. 解析/生成日期时间值的文本表示时,java.time类默认使用ISO 8601 。
The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds . Instant
类表示UTC时间线上的时刻,分辨率为纳秒 。 That class can directly parse your input string without bothering to define a formatting pattern. 该类可以直接解析您的输入字符串,而无需费心定义格式设置模式。
Instant instant = Instant.parse ( "2011-08-12T20:17:46.384Z" ) ;
About java.time 关于java.time
The java.time framework is built into Java 8 and later. java.time框架内置于Java 8及更高版本中。 These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
. 这些类取代了麻烦的旧的旧式日期时间类,例如java.util.Date
, Calendar
和SimpleDateFormat
。
The Joda-Time project, now in maintenance mode , advises migration to the java.time classes. 现在处于维护模式的Joda-Time项目建议迁移到java.time类。
To learn more, see the Oracle Tutorial . 要了解更多信息,请参见Oracle教程 。 And search Stack Overflow for many examples and explanations. 并在Stack Overflow中搜索许多示例和说明。 Specification is JSR 310 . 规格为JSR 310 。
Where to obtain the java.time classes? 在哪里获取java.time类?
- Java SE 8 , Java SE 9 , and later Java SE 8 , Java SE 9和更高版本
- Built-in. 内置的
- Part of the standard Java API with a bundled implementation. 标准Java API的一部分,具有捆绑的实现。
- Java 9 adds some minor features and fixes. Java 9添加了一些次要功能和修复。
- Java SE 6 and Java SE 7 Java SE 6和Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport . java.time的许多功能在ThreeTen- Backport中都被反向移植到Java 6和7。
- Android 安卓系统
- Later versions of Android bundle implementations of the java.time classes. 更高版本的Android捆绑了java.time类的实现。
- For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). 对于较早的Android, ThreeTenABP项目改编了ThreeTen-Backport (如上所述)。 See How to use ThreeTenABP… . 请参阅如何使用ThreeTenABP… 。
The ThreeTen-Extra project extends java.time with additional classes. ThreeTen-Extra项目使用其他类扩展了java.time。 This project is a proving ground for possible future additions to java.time. 该项目为将来可能在java.time中添加内容提供了一个试验场。 You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more . 您可以在这里找到一些有用的类,比如Interval
, YearWeek
, YearQuarter
,和更多 。
#3楼
There are other ways to parse it rather than the first answer. 还有其他解析方法,而不是第一个答案。 To parse it: 要解析它:
(1) If you want to grab information about date and time, you can parse it to a ZonedDatetime
(since Java 8 ) or Date
(old) object: (1)如果要获取有关日期和时间的信息,则可以将其解析为ZonedDatetime
(因为Java 8 )或Date
(旧)对象:
// ZonedDateTime's default format requires a zone ID(like [Australia/Sydney]) in the end.
// Here, we provide a format which can parse the string correctly.
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME;
ZonedDateTime zdt = ZonedDateTime.parse("2011-08-12T20:17:46.384Z", dtf);
or 要么
// 'T' is a literal.
// 'X' is ISO Zone Offset[like +01, -08]; For UTC, it is interpreted as 'Z'(Zero) literal.
String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX";// since no built-in format, we provides pattern directly.
DateFormat df = new SimpleDateFormat(pattern);Date myDate = df.parse("2011-08-12T20:17:46.384Z");
(2) If you don't care the date and time and just want to treat the information as a moment in nanoseconds, then you can use Instant
: (2)如果您不在乎日期和时间,而只想将信息视为纳秒级的时间,则可以使用Instant
:
// The ISO format without zone ID is Instant's default.
// There is no need to pass any format.
Instant ins = Instant.parse("2011-08-12T20:17:46.384Z");
#4楼
You can use the following example. 您可以使用以下示例。
String date = "2011-08-12T20:17:46.384Z";String inputPattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";String outputPattern = "yyyy-MM-dd HH:mm:ss";LocalDateTime inputDate = null;String outputDate = null;DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputPattern, Locale.ENGLISH);DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputPattern, Locale.ENGLISH);inputDate = LocalDateTime.parse(date, inputFormatter);outputDate = outputFormatter.format(inputDate);System.out.println("inputDate: " + inputDate);System.out.println("outputDate: " + outputDate);
#5楼
This technique translates java.util.Date to UTC format (or any other) and back again. 此技术将java.util.Date转换为UTC格式(或任何其他格式),然后再次返回。
Define a class like so: 像这样定义一个类:
import java.util.Date;import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;public class UtcUtility {public static DateTimeFormatter UTC = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZoneUTC();public static Date parse(DateTimeFormatter dateTimeFormatter, String date) {return dateTimeFormatter.parseDateTime(date).toDate();
}public static String format(DateTimeFormatter dateTimeFormatter, Date date) {return format(dateTimeFormatter, date.getTime());
}private static String format(DateTimeFormatter dateTimeFormatter, long timeInMillis) {DateTime dateTime = new DateTime(timeInMillis);String formattedString = dateTimeFormatter.print(dateTime);return formattedString;
}
} }
Then use it like this: 然后像这样使用它:
Date date = format(UTC, "2020-04-19T00:30:07.000Z")
or 要么
String date = parse(UTC, new Date())
You can also define other date formats if you require (not just UTC) 如果需要,您还可以定义其他日期格式(不仅限于UTC)
#6楼
@John-Skeet gave me the clue to fix my own issue around this. @ John-Skeet为我提供了解决此问题的线索。 As a younger programmer this small issue is easy to miss and hard to diagnose. 作为一个年轻的程序员,这个小问题很容易遗漏并且很难诊断。 So Im sharing it in the hopes it will help someone. 因此,我希望分享它,希望对您有所帮助。
My issue was that I wanted to parse the following string contraining a time stamp from a JSON I have no influence over and put it in more useful variables. 我的问题是我想解析下面的字符串,与来自我没有影响的JSON的时间戳形成鲜明对比,并将其放入更有用的变量中。 But I kept getting errors. 但是我不断出错。
So given the following (pay attention to the string parameter inside ofPattern(); 因此,给出以下内容(注意Pattern()内的字符串参数;
String str = "20190927T182730.000Z"LocalDateTime fin;
fin = LocalDateTime.parse( str, DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss.SSSZ") );
Error: 错误:
Exception in thread "main" java.time.format.DateTimeParseException: Text
'20190927T182730.000Z' could not be parsed at index 19
The problem? 问题? The Z at the end of the Pattern needs to be wrapped in 'Z' just like the 'T' is. 就像“ T”一样,模式末尾的Z需要用“ Z”包裹。 Change "yyyyMMdd'T'HHmmss.SSSZ"
to "yyyyMMdd'T'HHmmss.SSS'Z'"
and it works. 将"yyyyMMdd'T'HHmmss.SSSZ"
更改为"yyyyMMdd'T'HHmmss.SSS'Z'"
。
Removing the Z from the pattern alltogether also led to errors. 从样式中完全删除Z也会导致错误。
Frankly, I'd expect a Java class to have anticipated this. 坦白地说,我希望Java类已经预见到这一点。
这个日期格式是什么? 2011-08-12T20:17:46.384Z相关推荐
- Excel日期格式在matlab中的转换
Excel支持的日期格式如下:2011*8*12,*可以为"年"."/"."-"等形式,然而使用xlsread函数后肯定会转为字符串格式,不 ...
- excel matlab日期,Excel日期格式在matlab中的转换
Excel支持的日期格式如下:2011*8*12,*可以为"年"."/"."-"等形式,然而使用xlsread函数后肯定会转为字符串格式,不 ...
- Fri Oct 7 10:08:00 UTC 0800 2016日期格式转换为 yyyy-mm-dd hh24:mi:ss (Map实现版)
更新: 枚举实现版本请看点击打开链接 --------------------------------------------------------------------------------- ...
- 日期格式转换 java 2016-09-03T00:00:00.000+08:00
/** * 日期格式转换yyyy-MM-dd'T'HH:mm:ss.SSSXXX (yyyy-MM-dd'T'HH:mm:ss.SSSZ) TO yyyy-MM-dd HH:mm:ss * ...
- 1900-01-01t00:00:00+08:00 java_日期格式转换 java 2016-09-03T00:00:00.000+08:00
标签: /** * 日期格式转换yyyy-MM-dd'T'HH:mm:ss.SSSXXX TO yyyy-MM-dd HH:mm:ss * @throws ParseException */ pu ...
- C#日期格式精确到毫秒 !!
有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2009-6-24 14:33:34 如果要换成成200906,06-2009,2009-6-24或更多的该怎么办呢 我们要用到:DateT ...
- 电脑表格日期怎么修改原有日期_表格里日期格式怎么改
excel表格日期格式设置 excel 表格日期格式设置 篇一:如何在 excel 中设置日期时间格式 excel 中日期时间格式转换问题 1.2019/05/15 如何转换为 20190515 这种 ...
- iOS 日期格式转换
1.如何如何将一个字符串如" 20110826134106"装化为任意的日期时间格式,下面列举两种类型: NSString* string = @"20110826134 ...
- mysql insert 日期格式_MySQL的日期格式
MySQL的五种时间和日期类型 YEAR表示年份:字节数为1,取值范围为"1901--2155" DATE表示日期:字节数为4,取值范围为"1000-01-01--999 ...
最新文章
- python环境问题踩坑
- php鼠标经过显示文本,jQuery实现鼠标单击网页文字后在文本框显示的方法
- Postman全局变量的使用
- 你到底有几个邮箱?码云账号增加多邮箱支持!
- IBM存储部分常见配件PN号查询及描述翻译
- /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found错误的解决
- unity创建和销毁对象_如何创建和销毁对象
- IntelliJ IDEA for Mac如何查看某个方法的实现
- 825. 适龄的朋友
- 中livechart显示大数据_Servlet中利用jdbc加载显示数据
- 16. jQuery - 获取并设置 CSS 类
- 利用Minify加速 优化网站性能教程
- clion解决中文乱码的问题
- 计算机专业电路基础高考试卷,计算机专业电路基础试题(4页)-原创力文档
- 【37期】请你详细说说类加载流程,类加载机制及自定义类加载器
- ADS129X芯片中文资料(二)——模拟功能部分介绍
- 【LaTeX】表格调整行高、列宽、合并显示等操作
- EasyClick IOS 自动化测试 使用前置准备
- v1 中兴f450g_上海电信中兴F450G v2.0 改桥接
- 安卓应用调用QQ登录接口