简体   繁体   English

如何将此日期时间格式转换为Unix时间戳

[英]how to convert this datetime format into unix timestamp

I tried to parse this date 2017-03-04**T**17:20:55Z to Unix timestamp and I received a parse error for the T char (bolded it). 我试图将此日期2017-03-04**T**17:20:55Z解析为Unix时间戳,我收到了T字符的解析错误(将其粘合)。

I tried to use new SimpleDateFormat and DateTimeFormatter. 我尝试使用新的SimpleDateFormat和DateTimeFormatter。 How can I get a Unix timestamp from this DateTime format? 如何从这种DateTime格式获取Unix时间戳?

You can use single quotes to escape characters in the format string of SimpleDateFormat : 您可以使用单引号将SimpleDateFormat格式字符串中的字符转义:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date date = dateFormat.parse("2017-03-04T17:20:55Z");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM