class="java" name="code">package test; import java.util.Date; public class Test { public static void main(String[] args) throws Exception { t1(); t2(); } /** * 日期对象转换为时间戳 */ public static void t1(){ Date date = new Date(); long times = date.getTime(); System.out.println(times); //输出结果:1386665346113 } /** * 时间戳转换为日期对象 */ public static void t2(){ long times = 1386665666777L; Date date = new Date(times); System.out.println(date); //输出结果:Tue Dec 10 16:54:26 CST 2013 } }
?