How do I increment a java.sql.Timestamp by 14 days?

后端 未结 4 2060
借酒劲吻你
借酒劲吻你 2020-12-09 08:47

I have an app that takes a Timestamp as a boundary for the start date and end date of a sql selection, I want to populate a hashmap with weeks this year since the first mon

4条回答
  •  猫巷女王i
    2020-12-09 09:05

    private Long dayToMiliseconds(int days){
        Long result = Long.valueOf(days * 24 * 60 * 60 * 1000);
        return result;
    }
    
    public Timestamp addDays(int days, Timestamp t1) throws Exception{
        if(days < 0){
            throw new Exception("Day in wrong format.");
        }
        Long miliseconds = dayToMiliseconds(days);
        return new Timestamp(t1.getTime() + miliseconds);
    }
    

提交回复
热议问题