Java String 时间戳转换为 yyyy-MM-dd 格式
可以使用 SimpleDateFormat 类来将 String 类型的日期时间戳转换为指定格式的日期。代码如下:
String dateString = '2023615';
SimpleDateFormat sdf = new SimpleDateFormat('yyyyMMdd');
Date date = sdf.parse(dateString);
sdf.applyPattern('yyyy-MM-dd');
String formattedDate = sdf.format(date);
System.out.println(formattedDate);
输出结果为:2022-03-15。
原文地址: https://www.cveoy.top/t/topic/oDVx 著作权归作者所有。请勿转载和采集!