简体   繁体   English

如何通过DB设置倒数计时器的开始时间和结束时间? C#ASP.NET

[英]How to set a countdown timer with a start time and an end time from the DB? C# ASP.NET

Inside my DB I have stored a DateTime value for "StartDate" and "EndDate", and was wondering how I would create a countdown timer using these two values? 在我的数据库内部,我为“ StartDate”和“ EndDate”存储了DateTime值,并且想知道如何使用这两个值创建倒数计时器?

I have managed to use a timer to create a countdown with one value but not two. 我设法使用一个计时器来创建一个具有一个值而不是两个值的倒计时。 Is there a way to do this? 有没有办法做到这一点? I am currently working with ASP.NET, C# and SQL. 我目前正在使用ASP.NET,C#和SQL。

I think you can use Ticks. 我认为您可以使用Ticks。 Place some string into your database and save the ticks value. 将一些字符串放入数据库并保存ticks值。 It's almost like guid's.. It will never repeat. 这几乎像guid的。.它将永远不会重复。 Something like that: 像这样:

private string ReturnUniqueTick()
{
    return DateTime.Now.Ticks.ToString();
}

And then you create an index for this field in your database, what will ensure you will have an unique number or formatted string.. 然后,在数据库中为此字段创建索引,这将确保您拥有唯一的数字或带格式的字符串。

Hope this help. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM