java如何让带T的时间格式化
作者:苍穹之跃 时间:2022-12-22 10:44:28
java带T的时间格式化
public static void main(String[] args) {
String s = "2022-12-05T00:00:00Z";
LocalDateTime parse = LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"));
System.out.println(parse);
}
将带有‘T’的时间字符串转换成yyyy-MM-dd HH:mm:ss 格式
看代码:
//将带有T的时间字符串转换成yyyy-MM-dd HH:mm:ss
public static String convertDate(String strDate) {
String str = "";
try {
String fmt = "yyyy-MM-dd HH:mm:ss";
strDate = strDate.replace("T", " ");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(fmt);
return dateTimeFormatter.format(dateTimeFormatter.parse(strDate));
} catch (Exception ex) {
ex.printStackTrace();
}
return str;
}
public static void main(String args[]) throws ParseException {
String startDateTime = "2020-05-01T00:00:00";
String s = convertDate(startDateTime);
System.out.println(s);
}
结果:
来源:https://blog.csdn.net/wenxingchen/article/details/128534100
标签:java,带T,时间,格式化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java源码解析之String类的compareTo(String otherString)方法
2023-11-11 23:10:00
解决SpringBoot框架因post数据量过大没反应问题(踩坑)
2023-11-28 11:59:30
springboot对接支付宝支付接口(详细开发步骤总结)
2023-11-10 23:07:35
![](https://img.aspxhome.com/file/2023/6/58746_0s.png)
java private关键字用法实例
2022-01-16 10:08:06
c#中使用BackgroundWorker的实现
2023-05-04 08:51:01
![](https://img.aspxhome.com/file/2023/6/98226_0s.png)
Java%(取模运算)全面讲解
2022-03-02 06:11:34
C#获取每个年,月,周的起始日期和结束日期的方法
2023-11-11 20:53:45
C#在子线程中更新窗口部件的写法
2022-04-01 09:57:50
Input系统之InputReader处理触摸事件案例
2022-12-18 07:32:35
详解Mybatis的二级缓存配置
2023-03-20 10:48:37
SpringBoot+微信小程序实现文件上传与下载功能详解
2023-01-17 15:56:39
![](https://img.aspxhome.com/file/2023/2/97782_0s.jpg)
Android实现美女拼图游戏详解
2023-10-16 21:11:15
![](https://img.aspxhome.com/file/2023/8/95968_0s.gif)
Android中一种巧妙的drawable.xml替代方案分享
2021-12-06 04:18:35
![](https://img.aspxhome.com/file/2023/9/138829_0s.png)
C#中使用XmlDocument类来创建和修改XML格式的数据文件
2023-09-19 16:33:45
基于jdk1.8的Java源码详解 Integer
2023-05-08 11:32:22
![](https://img.aspxhome.com/file/2023/8/68158_0s.jpg)
C#中async和await的深入分析
2023-09-14 17:11:20
![](https://img.aspxhome.com/file/2023/5/106435_0s.jpg)
Spring Boot之AOP配自定义注解的最佳实践过程
2023-01-27 17:41:02
![](https://img.aspxhome.com/file/2023/4/77334_0s.gif)
浅谈Android Studio 3.0 的一些小变化
2022-12-23 10:27:56
![](https://img.aspxhome.com/file/2023/1/126691_0s.png)
C#发送数据到剪贴板及从剪贴板中取数据的方法
2021-06-06 15:28:38
基于c# 接口的实例详解
2023-10-22 22:22:11