tracking system - c# RRS feed

  • Question

  • User-1101529841 posted


    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).


    Thursday, January 21, 2016 6:03 AM


  • User1401801381 posted


    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())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 21, 2016 6:27 AM

All replies