Java特殊日期格式转换

格式示例:2020-01-13T16:00:00.000Z

	public static void main(String[] args) {
		String dateTime = "2020-01-13T16:00:00.000Z";
		dateTime = dateTime.replace("Z", " UTC");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
		SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date time = format.parse(dateTime);
			String result = defaultFormat.format(time);
			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

返回值:

2020-01-14 00:00:00



格式示例:2023-06-08T08:02:52

public static void main(String[] args) throws ParseException {

		String cellNode="2023-06-08T08:02:52";
		//a转为正常日期
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		Date  datea = df.parse(cellNode);
		DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String formatss = df2.format(datea);
		System.out.println(formatss);

	}

返回值:

2023-06-08 08:02:52



格式示例:2023-06-08T08:02:52.000+00:00

	public static void main(String[] args) throws ParseException {

		String cellNode="2023-06-08T08:02:52.000+00:00";
		//a转为正常日期
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
		Date  datea = df.parse(cellNode);
		SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
		Date date1 =  df1.parse(datea.toString());
		DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String formatss = df2.format(date1);
		System.out.println(formatss);

	}

返回值:

2023-06-08 16:02:52



格式示例:2021-05-14T23:30:35+08:00

public static void main(String[] args) throws ParseException {

		String a = "2021-05-14T23:30:35+08:00";
		LocalDateTime date = LocalDateTime.parse(a, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
		String dateString = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		System.out.println(""+dateString);

	}

返回值:

2021-05-14 23:30:35

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

儿时可乖了

混口饭吃,大佬们,赏点吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值