判断一个status的状态,如果状态为1开始计时,并将时间存入数据库,请问该怎么做?

新手上路,请多包涵
// If the status is 1, the time will be recorded and stored in the database, MySQL database
if (status == 1) {
 long start = System.currentTimeMillis();
} else if (status != 1) {
 // 具体的实现逻辑
 // If the status is 0, the recording time is stopped and the start time and stop time are intercepted into the database
 // long end = System.currentTimeMillis();
 // 具体的实现逻辑
}
// 数据保存到数据库中
data.setStVal(Integer.valueOf(status));
data.setUpdateTime(new Date());
iec61850DataService.updateById(data);

问题描述

这个需求是需要对一个程序进行的状态进行判定,如果状态为1,就进行计时,格式为:记录时间 2020-11-09 17:25:21,如果状态为0,则停止计时,请各位大佬帮忙想想办法,谢谢

阅读 1.8k
1 个回答
if (status == 1) {
 data.setStart(System.currentTimeMillis());
} else {
 data.setEnd(System.currentTimeMillis());
}
updateById(data);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题