开发者

Is System.DateTime client dependant?

开发者 https://www.devze.com 2023-01-31 21:10 出处:网络
I was working on an attendance system on ASP.Net where the entire week\'s dates are calculated by my program based on the current date开发者_运维百科. I am using DateTime.Today. I was apprehensive to

I was working on an attendance system on ASP.Net where the entire week's dates are calculated by my program based on the current date开发者_运维百科. I am using DateTime.Today. I was apprehensive to use this as I feel that users can modify this date by merely changing their system clock and mark previous week's attendance.

Can DateTime.Today be changed by changing system clock on client side? If yes, is there something else I can use instead of that?


DateTime.Today will return the value on the computer it is run on.

In an ASP.NET page, this will be the server.

There is no way that the client browser will be able to modify this value.

If you are using the class within a client based technology (say silverlight), or using a custom client application and using DateTime.Today within it directly, then yes, the client date/time will be used and could be changed by the client.


DateTime.Now will always give the time used on the server and not on client computer.

You can also use DateTime.UtcNow


In an ASP.NET app, DateTime.Today should be the date/time on the server and not adjustable by the end user, so you should be fine.


You should have all of your times in UTC format, on the server. Use DateTime.UtcNow. I would suggest keeping the user's timezone offset in your database somewhere and then adjusting from there for display purposes.

0

精彩评论

暂无评论...
验证码 换一张
取 消