本文介紹了將日期從 8 月 14 日格式化為 YYYYMMDD的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
將日期 2011 年 8 月 14 日更改為格式 20110814 .. 我如何在 java 中做到這一點(diǎn)?
Change the date 14 aug 2011 to the format 20110814 .. how can i do that in java ?
這里 14aug 是一個(gè)字符串 ... String date="14aug";
Here 14aug is a string ... String date="14aug";
推薦答案
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String yyyyMMdd = sdf.format(date);
參考:java.text.SimpleDateFormat
更新:精英紳士的問題很重要.如果你以 String
開頭,那么你應(yīng)該首先解析它以獲取上例中的 date
對(duì)象:
Update: the question by The Elite Gentleman is important. If you start with a String
, then you should first parse it to obtain the date
object from the above example:
Date date = new SimpleDateFormat("dd MMM yyyy").parse(dateString);
這篇關(guān)于將日期從 8 月 14 日格式化為 YYYYMMDD的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!