SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String yyyyMMdd = sdf.format(date);
Reference: java.text.SimpleDateFormat
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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…