客户端时间和服务器时间之间的同步

问题描述:

我的Winform应用程序在客户端计算机上运行,​​它将与服务器上的Sql server数据库进行交互



通过我的应用程序开发,我愚蠢地使用了Datetime。现在获取查询,跟踪等条目的日期和时间



但我知道用户可能会错过使用它就像在3月23日使用系统进行数据输入日期定在2月23日,声称他已经完成了他的工作





所以我想要的是一个更好的解决方案来同步数据库日期时间。我已经在应用程序启动时和固定时间间隔内将系统时间与服务器的getdata()值进行比较,但是也有可能在定义的时间间隔内更改时间

任何人都可以提出更好的建议吗?

My Winform application run on the client machine and it will interact with the Sql server database on the Server

All through my application developement i had foolisingly used Datetime.Now to get the date and time of entries to queries ,tracking etc

But i know that the user can miss use it like making a dataentry on 23 march with the system date set to 23rd of february and claiming he had already done his work


So what I want is a better solution to synchronise with the database datetime .I had already done it with comparing the system time with the getdata() value of the Server at application start and within fixed interval but then also there is a chance of changing time within the defined intervals
can anyone suggest better idea ?

在服务器上执行此操作:SQL支持GetDate方法:



Do it at the Server instead: SQL supports the GetDate method:

INSERT INTO myTable (UserID, entryTimeStamp) VALUES('12345', GETDATE())

>