简体   繁体   中英

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).

I tried to use new SimpleDateFormat and DateTimeFormatter. How can I get a Unix timestamp from this DateTime format?

You can use single quotes to escape characters in the format string of SimpleDateFormat :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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