java字符串日期格式化
时间: 2023-08-31 11:09:26 浏览: 48
在Java中,可以使用SimpleDateFormat类来格式化日期字符串。以下是一个简单的示例:
```java
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatExample {
public static void main(String[] args) {
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = formatter.format(now);
System.out.println(formattedDate);
}
}
```
在上述示例中,我们使用SimpleDateFormat类将当前日期格式化为“yyyy-MM-dd HH:mm:ss”的字符串。其中,yyyy表示年份,MM表示月份,dd表示日期,HH表示小时,mm表示分钟,ss表示秒。
你可以根据需要使用不同的格式字符串对日期进行格式化。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/octet-stream](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![text/plain](https://img-home.csdnimg.cn/images/20250102104920.png)