判断是否超过24小时(一天)的方法2
Posted sensen~||^_^|||&
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断是否超过24小时(一天)的方法2相关的知识,希望对你有一定的参考价值。
//判断是否离线
private Boolean isTOday(String time)
Date today = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String format = dateFormat.format(today);
String substring = time.substring(0, 10);
if (format.equals(substring))
return true;
else
return false;
private Boolean isTOday(String time)
Date today = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String format = dateFormat.format(today);
String substring = time.substring(0, 10);
if (format.equals(substring))
return true;
else
return false;
eg:
for (TvmStatusDTO list :statusDTOList)
if(!StringUtils.isEmpty(list.getModifyTime()))
Boolean tOday = isTOday(list.getModifyTime());
if (!tOday)
list.setServiceStatus("");
timeLIst.add(list.getModifyTime());
for (TvmStatusDTO list :statusDTOList)
if(!StringUtils.isEmpty(list.getModifyTime()))
Boolean tOday = isTOday(list.getModifyTime());
if (!tOday)
list.setServiceStatus("");
timeLIst.add(list.getModifyTime());
Update修改方法判断该ID的数据是否超过24小时,超过不许修改
@PostMapping("/update") public Result projectUpdate(@RequestBody ProjectVoEntity projectvo) throws ParseException { //获取项目id ProjectEntity project = projectService.selectById(projectvo.getProjectid()); //获取项目分类id ClassesEntity ce = classesService.selectById(projectvo.getClassid()); //判断项目id是否存在 if(project!=null) { //时间转换 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //获取创建时间 Date ss=project.getCretime(); //Date转String String sstr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ss); //创建时间 Date stt = sdf.parse(sstr); //当前时间 Date sttt = new Date(); //当前时间减去创建时间 long cha = sttt.getTime() - stt.getTime(); boolean flag; if(cha<0){ flag= false; } double result = cha * 1.0 / (1000 * 60 * 60); if(result<=24){ project.setProjectid(projectvo.getProjectid()); project.setPname(projectvo.getPname()); //修改项目分类id project.setClassid(ce.getClassid()); project.setStartday(sdf.parse(projectvo.getStartday())); project.setEndday(sdf.parse(projectvo.getStartday())); project.setProanalysis(projectvo.getProanalysis()); project.setUnderent(projectvo.getUnderent()); project.setBudgetmoney(new BigDecimal(projectvo.getBudgetmoney())); project.setProschedule(projectvo.getProschedule()); project.setProplan(projectvo.getProplan()); project.setYear(projectvo.getYear()); project.setEditstate("true"); projectService.updateById(project); flag= true; }else{ flag= false; project.setEditstate("false"); projectService.updateById(project); return Result.error("false"); } }else { return Result.error("项目ID不存在"); } return Result.ok(); }
以上是关于判断是否超过24小时(一天)的方法2的主要内容,如果未能解决你的问题,请参考以下文章