1. 程式人生 > >java獲取當前時間的時間戳和後7天的時間戳

java獲取當前時間的時間戳和後7天的時間戳

話不多說,看程式碼

public class AppTime {

    public static void main(String[] args) {

        Calendar calendar = Calendar.getInstance();
        long createTime = calendar.getTimeInMillis();
        System.out.println(createTime);   //1541235267116
        SimpleDateFormat form1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String res = form1.format(createTime);
        System.out.println(res);  //2018-11-03 16-54-27

        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 7);
        System.out.println(calendar.getTimeInMillis());   //1541840067116

        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String result = format.format(today);
        System.out.println(result);  //2018-11-10 16-54-27

    }
}