JAVA时间加减操作

    @ApiOperation("时间加减操作")
    private Date getChangeTime(Date nowTime,Long changeValue)
    {
        //nowTime=基础时间,将在此时间上做加减
        //changeValue=时间变换量,如changeValue=60,则获取[基础时间]60秒后的时间
            //如 changeValue=-60 ,则获取[基础时间]60秒前的时间
        Date newTime =new Date(nowTime.getTime()+ 1000L * changeValue);
        return newTime;
    }

    
    //如:获取当前时间100秒以后的时间:
    Date nowDate = new Date(); //获取当前时间
    Date newDate = getChangeTime(nowDate,100L);


    @ApiOperation("时间Date转LocalDateTime")
    private LocalDateTime DateToLocalDateTime(Date locTime)
    {
        String firstString= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locTime);
        LocalDateTime firstTime = LocalDateTime.parse(firstString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return firstTime;
    }

猜你喜欢

转载自blog.csdn.net/u012402739/article/details/121789667