提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用SimpleDateFormat设置日期格式
import java.text.SimpleDateFormat; import java.util.Date; /*来自 nowjava - 时代Java*/ public class Main { public static void main(String[] args) { Date date = new Date(); //formatting day in d format like 1,2 etc String strDateFormat = "d"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current day in d format : " + sdf.format(date)); /** N o w J a v a . c o m 提 供 **/ //formatting day in dd format like 01, 02 etc. strDateFormat = "dd"; sdf =