Last post Jan 21, 2016 09:43 AM by gerrylowry
Jan 21, 2016 06:03 AM|ramiwahdan|LINK
I have made a tracking system to track all the movements of a user from login to logout. I am storing the times for that as well (for every movement). The system is ok but it is saving the time of the (hosting company server). for Example now it is 10AM
in my time but when i view the logfile it show 9PM and date is 20-1-2016 and today it is 21-1-2016. So it is taking server time and date. How can i re-write the string to take the difference (which i believe it is +12 or +11).
Jan 21, 2016 06:23 AM|anuj_koundal|LINK
Convert time according to your local timezone. Check this:
Jan 21, 2016 06:27 AM|sam_xiii|LINK
Always the UTC time (like DateTime.UtcNow) so you will not have problems with different servers and you can display the date according to your user location.
If you want to show the time for your area you can use the TimeZoneInfo class
So let's say you are in china you can do that
var date = DateTime.UtcNow;
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
Console.WriteLine(TimeZoneInfo.ConvertTimeFromUtc(date,tzi));// display the time in china
if you want to get all possible timezones you can do
foreach(TimeZoneInfo tz in TimeZoneInfo.GetSystemTimeZones())
http://www.sambeauvois.be | @sambeauvois
Jan 21, 2016 09:43 AM|gerrylowry|LINK
@ramiwahdan welcome to forums.asp.net
(simplified) anything done server side will be either the server's local time or UTC depending on which .NET framework methods you choose.
if you're writing programs that are using dates, you need to understand date and time issues and formats.
study these articles:
For logging and tracking, UTC is the best because you are using ASP.NET and likely you are not showing the date to your end-user.
UTC is not affected by Daylight Saving Time.
unless you have a really strong need to show local time on the end users display, i would not bother with getting the date and time from your end user's computer.