用java 写一个调试类,用DateFormat格式类将当前日期按以上四种格式打印出来; 提示:格式之一 DateFormat dfm = new SimpleDateFormat(“yyyy-mm-dd”);
时间: 2023-05-19 09:05:58 浏览: 54
以下是用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));
}
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)