import java.text.ParseException;
import java.text.SimpleDateFormat;
public class dateFormatUtil {
public static void main(String[] args) throws ParseException {
long time = System.currentTimeMillis();
System.out.println(time);
System.out.println(timeToFormat(time));
System.out.println(timeToSecond(timeToFormat(time)));
}
//13位毫秒时间戳 --> yyyy-MM-dd HH:mm:ss
public static String timeToFormat(long time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
return sdf.format(time);
}
//yyyy-MM-dd HH:mm:ss --> 13位毫秒时间戳
public static long timeToSecond(String date) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.parse(date).getTime();
}
}
还没有评论,来说两句吧...