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
以上就是天津卓眾教育java培訓機構(gòu)的小編針對“Java日期類型轉(zhuǎn)換實例”的內(nèi)容進行的回答,希望對大家有所幫助,如有疑問,請在線咨詢,有專業(yè)老師隨時為你服務(wù)。