java 時間字串和時間戳(長整形long)之間的互轉
阿新 • • 發佈:2019-02-20
import java.util.Date;
import java.text.SimpleDateFormat;
class Test {
public static void main(String[] args) {
Date date1 = new Date();
long l = date1.getTime();
System.out.println(l);
long date2 = System.currentTimeMillis();
System.out.println(date2);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date3 = sdf.format(new Date().getTime());
System.out.println(date3);
}
}