![](/img/trans.png)
[英]How to convert a local dateTime Object to a UTC java.util.Date
[英]How can I convert a java.util.Date object to the restricted form of the canonical representation of dateTime
我需要將java.util.Date變量轉換為類似於以下內容的表示形式。
1995-12-31T23:59:59.999Z
此日期字段的格式為1995-12-31T23:59:59Z,並且是dateTime規范表示的一種更受限制的形式http://www.w3.org/TR/xmlschema-2/#dateTime 。
尾部的“ Z”表示UTC時間,它是必需的。
您可以使用SimpleDateFormat
。
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(df.format(new Date()));
輸出:
2010-02-14T06:38:48.920Z
在這里,您將日期格式器上的時區手動設置為UTC。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.