Changing Java Date one hour back

后端 未结 11 1584
名媛妹妹
名媛妹妹 2020-11-30 20:47

I have a Java date object:

Date currentDate = new Date();

This will give the current date and time. Example:

Thu Jan 12 10:         


        
11条回答
  •  孤街浪徒
    2020-11-30 21:24

    Get the time in milliseconds, minus your minutes in milliseconds and convert it to Date. Here you need to objectify one!!!

        int minutes = 60;
        long currentDateTime = System.currentTimeMillis();
        Date currentDate = new Date(currentDateTime - minutes*60*1000);
        System.out.println(currentDate);
    

提交回复
热议问题