java 时间字符串和时间戳(长整形long)之间的互转

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);
    }
}

你可能感兴趣的:(Java)