為什么時(shí)間輸出結(jié)果不一樣,求解
package?com.imooc; import?java.text.ParseException; import?java.text.SimpleDateFormat; import?java.util.Date; public?class?TheLise?{ ????public?static?void?main(String[]?args)throws?ParseException?{ SimpleDateFormat?sb1=new?SimpleDateFormat("yyyy年MM月dd日HH時(shí)mm分ss秒"); SimpleDateFormat?sb2=new?SimpleDateFormat("yyyy/mm/dd?HH:mm"); SimpleDateFormat?sb3=new?SimpleDateFormat("yyyy-mm-dd?HH:mm:ss"); Date?b=new?Date(); System.out.println(sb1.format(b)); System.out.println(sb2.format(b)); System.out.println(sb3.format(b)); String?d="2019-7-6?16:07:13"; SimpleDateFormat?sb4=new?SimpleDateFormat("yyyy-MM-dd?HH:mm:ss"); Date?sb6=sb4.parse(d); System.out.println(sb6); ????}
結(jié)果
2019年07月24日17時(shí)34分50秒
2019/34/24 17:34
2019-34-24 17:34:50
Exception in thread "main" java.text.ParseException: Unparseable date: "2019-7-6 16:07:13"
?at java.text.DateFormat.parse(DateFormat.java:366)
?at com.imooc.TheLise.main(TheLise.java:17)
Process finished with exit code 1
2019-07-24
屬于不安全的轉(zhuǎn)換
需要trycatch起來
2020-03-08
但本質(zhì)上并沒有處理,所以會(huì)報(bào)出異常
2020-03-08
public static void main(String[] args) throws ParseException {? ? 章節(jié)中的異常是把它丟到更上一層了
2019-09-21
2019-08-21
這個(gè)是輸出當(dāng)前時(shí)間啊,肯定和i題目中的不一樣
2019-08-02
SimpleDateFormat類中 mm表示的是分鐘,MM表示的是月份。 你在年月日當(dāng)中的mm指的是分鐘而不是MM的月份,所以你現(xiàn)在月份中的34和后面時(shí)間中的34是同一個(gè)意思。34分鐘。
2019-07-25
應(yīng)該是yyyy/MM/dd HH:mm,你把前面MM寫成小寫了,小寫的代表的是分鐘,大寫的才代表是月。