日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java日期格式大全 format SimpleDateFormat

發布時間:2024/4/17 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java日期格式大全 format SimpleDateFormat 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?http://eternal1025.iteye.com/blog/344360

http://www.freejsp.net/Spring/13325.htm

1.日期型 轉換為 String
DateFormat?? f?? =?? new?? SimpleDateFormat( "yyyy-MM-dd?? hh:MM ");
String t=f.format(date);

2.String ->Date
Date date=Util.strToDateTimeYMD(t);


模板定義如下:
y???????????????? 年號,如?? 1996
M???????????????? 月份,如?? July?? 或者?? 07
d???????????????? 月中第幾天,如?? 12
H???????????????? 小時(24制),如?? 0、17
m???????????????? 分鐘,如?? 32
s???????????????? 鈔鐘,如55
S???????????????? 微鈔,如978
E???????????????? 星期幾,如?? Tuesday
D???????????????? 一年中的第幾天,如?? 189
w???????????????? week?? in?? year???????????????????????? (Number)???????????????????????? 27
W???????????????? week?? in?? month???????????????????? (Number)???????????????????????? 2
a???????????????? am/pm?? marker???????????????????????? (Text)???????????????????????????? PM
k???????????????? hour?? in?? day?? (1~24)???????????? (Number)???????????????????????? 24
K???????????????? hour?? in?? am/pm?? (0~11)???????? (Number)???????????????????????? 0
z???????????????? time?? zone???????????????????????????? (Text)???????????????????????????? Pacific?? Standard?? Time
'???????????????? escape?? for?? text???????????????? (Delimiter)
' '???????????? single?? quote???????????????????????? (Literal)

STRING格式
dow mon dd hh:mm:ss zzz yyyy其中:
dow 是一周中的某一天 (Sun, Mon, Tue, Wed, Thu, Fri, Sat)。?
mon 是月份 (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)。?
dd 是一月中的某一天(01 至 31),顯示為兩位十進制數。?
hh 是一天中的小時(00 至 23),顯示為兩位十進制數。?
mm 是小時中的分鐘(00 至 59),顯示為兩位十進制數。?
ss 是分鐘中的秒數(00 至 61),顯示為兩位十進制數。?
zzz 是時區(并可以反映夏令時)。標準時區縮寫包括方法 parse 識別的時區縮寫。如果不提供時區信息,則 zzz 為空,即根本不包括任何字符。?
yyyy 是年份,顯示為 4 位十進制數。 http://stackoverflow.com/questions/4993132/getting-java-lang-illegalargumentexception-illegal-pattern-character-o-while Actually from java docs I got that format for util's Date.toString() function
String java.util.Date.toString()

Converts this Date object to a String of the form:

dow mon dd hh:mm:ss zzz yyyy where:
  • dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
  • mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
  • dd is the day of the month (01 through 31), as two decimal digits.
  • hh is the hour of the day (00 through 23), as two decimal digits.
  • mm is the minute within the hour (00 through 59), as two decimal digits.
  • ss is the second within the minute (00 through 61, as two decimal digits.
  • zzz is the time zone (and may reflect daylight saving time). Standard time zone abbreviations include those recognized by the method parse. If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.
  • yyyy is the year, as four decimal digits.
Overrides: toString() in Object Returns:
a string representation of this date.
See Also:
java.util.Date.toLocaleString()
java.util.Date.toGMTString()

==========

http://java.chinaitlab.com/base/747297.html

24小時制時間顯示:

public class Datetime {

????public static void main(String args[]){
???????? java.util.Date current=new java.util.Date();
???????????java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
???????????String c=sdf.format(current);
???????????System.out.println(c);
????}
}

12小時制時間顯示:


public class Datetime {

????public static void main(String args[]){
???????? java.util.Date current=new java.util.Date();
???????????java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
???????????String c=sdf.format(current);
???????????System.out.println(c);
????}
}

兩者區別:yyyy-MM-dd HH:mm:ss?;? yyyy-MM-dd hh:mm:ss

如下:

字母日期或時間元素表示示例
GEra 標志符TextAD
yYear1996; 96
M年中的月份MonthJuly; Jul; 07
w年中的周數Number27
W月份中的周數Number2
D年中的天數Number189
d月份中的天數Number10
F月份中的星期Number2
E星期中的天數TextTuesday; Tue
aAm/pm 標記TextPM
H一天中的小時數(0-23)Number0
k一天中的小時數(1-24)Number24
Kam/pm 中的小時數(0-11)Number0
ham/pm 中的小時數(1-12)Number12
m小時中的分鐘數Number30
s分鐘中的秒數Number55
S毫秒數Number978
z時區General time zonePacific Standard Time; PST; GMT-08:00
Z時區RFC 822 time zone-0800

總結

以上是生活随笔為你收集整理的java日期格式大全 format SimpleDateFormat的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。