更新時(shí)間:2020-08-11 16:55:19 來源:動(dòng)力節(jié)點(diǎn) 瀏覽2712次
1、Date轉(zhuǎn)String
將日期格式化成指定的格式
Date?currentTime?=?new?Date();
SimpleDateFormat?formatter?=?new?SimpleDateFormat("yyyy-MM-dd?HH:mm:ss");
String?dateString?=?formatter.format(currentTime);
System.out.println(dateString);
輸出:
2018-09-23 11:19:47
2、String轉(zhuǎn)Date
注意:String和DateFormat樣式需一樣,不然無法解析
//?將date字符串轉(zhuǎn)化為日期
String?dateString?=?"2018年08月08日";
DateFormat?format?=?new?SimpleDateFormat("yyyy年MM月dd日");
Date?date?=?format.parse(dateString);
System.out.println(date.toString())
輸出:
Wed Aug 08 00:00:00 CST 2018
以上就是動(dòng)力節(jié)點(diǎn)java培訓(xùn)機(jī)構(gòu)的小編針對(duì)“Java日期類型轉(zhuǎn)換實(shí)例”的內(nèi)容進(jìn)行的回答,希望對(duì)大家有所幫助,如有疑問,請(qǐng)?jiān)诰€咨詢,有專業(yè)老師隨時(shí)為你服務(wù)。
相關(guān)閱讀
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)