import java.text.ParseException; import java.text.SimpleDateFormat; public static void main(String[] args) { String str = "20110101"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd"); try { System.out.println(format1.format(format.parse(str))); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
输出结果为2011-01-01
时间: 2024-10-08 11:44:28