locked
Storing Date time and Handling Date time RRS feed

  • Question

  • User2048898515 posted

    Hi Team,

    My Project is a appointment project where the user will pick the time slot and book it.

    Things were fine running fine in localhost, when i host in the azure server, date time stored is different than my local zone (Malaysian time). So the time stored was in US time.

    How to handle this scenario?

    when i pick the date and time how to make sure that time selected is in Malaysian time and stored as malaysian time, irrespective of where the server is.

    Wednesday, July 18, 2018 5:22 AM

Answers

  • User-369506445 posted

    hi

    you can convert the server time zone to your time zone

    var serverTime = DateTime.Now;
    
                var serverZone = TimeZoneInfo.FindSystemTimeZoneById("US Mountain Standard Time");
                var localZone = TimeZoneInfo.FindSystemTimeZoneById("Malay Peninsula Standard Time"); 

    var localTime = TimeZoneInfo.ConvertTime(serverTime, serverZone, localZone);

    note: just be sure about the correct name for time zones

    refer

    https://docs.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 18, 2018 5:34 AM

All replies

  • User-369506445 posted

    hi

    you can convert the server time zone to your time zone

    var serverTime = DateTime.Now;
    
                var serverZone = TimeZoneInfo.FindSystemTimeZoneById("US Mountain Standard Time");
                var localZone = TimeZoneInfo.FindSystemTimeZoneById("Malay Peninsula Standard Time"); 

    var localTime = TimeZoneInfo.ConvertTime(serverTime, serverZone, localZone);

    note: just be sure about the correct name for time zones

    refer

    https://docs.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 18, 2018 5:34 AM
  • User283571144 posted

    Hi nambir,

    If you use azure web app, we could change the server time zone .

    You could add an application setting (using the portal) called “WEBSITE_TIME_ZONE” equal to the name of the time zone in question (basically the same string as the key name at HKLM\Software\Microsoft\Windows Nt\CurrentVersion\Time Zones\). 

    If you use azure VM, it is not recommended you try to change the Time Zone, you should rather use methods like TimeZoneInfo.ConvertTimefromUTCTime in your code (.Net).

    More details, you could refer to below article:

    https://msdn.microsoft.com/en-us/library/ms973825.aspx 

    Best Regards,

    Brando

    Thursday, July 19, 2018 1:02 PM