Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

判断一个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,则停止计时,请各位大佬帮忙想想办法,谢谢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
if (status == 1) {
 data.setStart(System.currentTimeMillis());
} else {
 data.setEnd(System.currentTimeMillis());
}
updateById(data);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...