是否可以在数据库中保存正在运行的计时器?
例如。假设我创建了一个计时器实体,它能够保存正在运行的计时器的单独记录?
据我所知,存储在数据库中的内容必须是静态的。那么有没有办法在数据库中保存非静态记录呢?
最佳答案
.NET 中的秒表类所做的就是记下启动秒表的时间,然后当您查看结果时,它只是从停止/当前时间中减去开始时间。
这很简单
create table Stopwatches
(
Id int identity(1,1) primary key clustered,
StartTime DateTime not null,
EndTime DateTime null
)
启动秒表
insert into Stopwatches (StartTime) values (GetDate())
select @@IDENTITY as StopwatchId;
停止秒表
update Stopwatches
set EndTime = GetDate()
where id = @stopwatchId
查看已过去的时间
select DateDiff(second, StartTime, EndTime) as Elapsed where id = @stopwatchId
关于c# - 是否可以在数据库中保存正在运行的计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22827840/