字符串轉化為日期格式 Java中怎么把字符串轉換成日期格式?。?/h1>
Java中怎么把字符串轉換成日期格式?。咳绻雽⑷掌谳敵鰹?005年6月9日,我們可以這樣寫:simpledateformat SDF=new simpledateformat(“yyy-MM-DD
Java中怎么把字符串轉換成日期格式???
如果您想將日期輸出為2005年6月9日,我們可以這樣寫:simpledateformat SDF=new simpledateformat(“yyy-MM-DD”)string str=sdf.format格式(parse(“2005-06-09 00:00:00”)str將以我們設置的格式輸出。使用的API是SimpleDataFormat,它屬于java.text.SimpleDataFormat所以請記住導入!用法:simpledateformat SDF=new simpledateformat(“yyy-MM-DD HH:MM:SS”)是最重要的一行,它建立了轉換的格式。Yyyy是一年中完整的一年,mm是月份,DD是日期。擴展數(shù)據(jù):simpledateformat支持以下格式:YY/mm/DD HH:mm:SS如“2017/12 17:55:00”YY/mm/DD HH:mm:SS PM如“2017/12 17:55:00 PM”YY mm DD HH:mm:SS如“2017-12 17:55:00”YY mm DD HH:mm:SS am如“2017-12 17:55:00 am”
怎樣把日期字符串轉換成日期格式?
在Java中,要將字符串轉換為日期格式,您需要在simpleDataFormat類中使用parse方法。format方法傳入的參數(shù)的格式含義是:yyyy:表示四位數(shù)的年,mm:表示月,DD:表示日,HH:表示24小時,HH:表示12小時,mm:表示分鐘,SS:表示秒。有關詳細信息,請參見示例:simpledateformat SDF=new simpledateformat(“yyyy-MM-dd”)Date=解析sdf.parse("2016-06-06") 系統(tǒng)輸出打印( sdf.format格式(date))輸出結果為:2016-06-simpledateformat SDF=new simpledateformat(“yyyy-MM-DD HH:MM:SS”)date日期=解析sdf.parse("2016-06-06 16:24:50") 系統(tǒng)輸出打印( sdf.format格式(日期)輸出結果:2016-06-06 16:24:50