用java 写一个调试类,用DateFormat格式类将当前日期按以上四种格式打印出来; 提示:格式之一 DateFormat dfm = new SimpleDateFormat(“yyyy-mm-dd”);
时间: 2023-05-19 22:05:58 浏览: 73
java代码-使用java解决比较日期,Date类DateFormat类的源代码
以下是用Java编写的调试类,使用DateFormat格式类将当前日期按四种格式打印出来:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DebugClass {
public static void main(String[] args) {
DateFormat dfm1 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat dfm2 = new SimpleDateFormat("yyyy/MM/dd");
DateFormat dfm3 = new SimpleDateFormat("MM-dd-yyyy");
DateFormat dfm4 = new SimpleDateFormat("dd/MM/yyyy");
Date currentDate = new Date();
System.out.println("Current date in yyyy-MM-dd format: " + dfm1.format(currentDate));
System.out.println("Current date in yyyy/MM/dd format: " + dfm2.format(currentDate));
System.out.println("Current date in MM-dd-yyyy format: " + dfm3.format(currentDate));
System.out.println("Current date in dd/MM/yyyy format: " + dfm4.format(currentDate));
}
}
阅读全文