直接贴代码,不解释:
package com.chapter.five.one.tcn; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class TestDate2 { public static void main(String[] args) throws ParseException { DateFormat df = new SimpleDateFormat("HHhhss"); Date pp = df.parse("102030"); //System.out.println(pp); DateFormat p1p = new SimpleDateFormat("HH:mm:ss"); System.out.println(p1p.format(pp)); } }
输出:
10:00:30
第二段:
package com.chapter.five.one.tcn; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class TestDate2 { public static void main(String[] args) throws ParseException { DateFormat df = new SimpleDateFormat("yyyyMMddHHhhss"); Date pp = df.parse("20081002102030"); //System.out.println(pp); DateFormat p1p = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(p1p.format(pp)); } }
输出:
2008-10-02 10:00:30
时间: 2025-01-20 21:06:18