java中日期转换

以下是常用的格式化字符串:
y Year Year
M Month in year Month
w Week in year Number
W Week in month Number
D Day in year Number
d Day in month Number
F Day of week in month Number
E Day in week Text
a Am/pm marker Text
H Hour in day (0-23) Number
k Hour in day (1-24) Number
K Hour in am/pm (0-11) Number
h Hour in am/pm (1-12) Number
m Minute in hour Number
s Second in minute Number
S Millisecond Number
z Time zone General time zone
Z Time zone RFC 822 time zone
以下是两个示例:

public static String getGmtDate() {
DateFormat df = new SimpleDateFormat(“d MMM yyyy HH:mm:ss z”, Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone(“GMT”));
return (df.format(new Date()));
}
public static String getUtcDate() {
DateFormat gmtFormat = new SimpleDateFormat(“yyyyMMdd’T’HHmmss.SSS’Z'”);
Calendar calendar = java.util.Calendar.getInstance();
return gmtFormat.format(calendar.getTime());
}

此条目发表在java/j2ee分类目录,贴了, 标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据