java 日期转rfc3339 格式

xiaoxiao2021-02-28  84

this would be done using different SimpleDateFormat patterns.

Here a list of patterns for the individual declarations in RFC 3339:

date-fullyear: yyyy date-month: MM date-mday: dd time-hour: HH time -minute: mm time-second: ss time-secfrac: .SSS (S means millisecond, though - it is not clear what would happen if there are more or less than 3 digits of these.) time-numoffset: (like +02:00 seems to be not supported - instead it supports the formats +0200, GMT+02:00 and some named time zones using z and Z.) time-offset: 'Z' (not supporting other time zones) - you should use format.setTimezone(TimeZone.getTimeZone("UTC")) before using this.) partial-time: HH:mm:ss or HH:mm:ss.SSS. full-time: HH:mm:ss'Z' or HH:mm:ss.SSS'Z'. full-date: yyyy-MM-dd date-time: yyyy-MM-dd'T'HH:mm:ss'Z' or yyyy-MM-dd'T'HH:mm:ss.SSS'Z'

As we can see, this seems not to be able to parse everything. Maybe it would be a better idea to implement an RFC3339DateFormat from scratch (using regular expressions, for simplicity, or parsing by hand, for efficiency).

so,just the below is what i want

System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") .format(new Date())); 参考:https://stackoverflow.com/questions/6038136/how-do-i-parse-rfc-3339-datetimes-with-java

   https://stackoverflow.com/questions/289311/output-rfc-3339-timestamp-in-java

   http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html#iso8601timezone

   

转载请注明原文地址: https://www.6miu.com/read-45598.html

最新回复(0)