I have a service that is writing data into Azure database. However Azure automatically writes these "TimeStamps" in UTC. Due to I am not in UTC zone, my TimeStamps are not correct. After some investigations, I understood that there are several options. I am having hard times to understand which one should I use? Currently it is hard to see all possible problems that may appear in the future.
Here is my model:
public class DataRecord : IDataRecord
{
public int Id { get; set; }
public DateTime TimeNow { get; set; }
}
So currently Azure don't care in which zone I am and just writes this DateTime time in UTC.
Possible options (I understood) I have:
- Change DateTime into string and then parse back into DateTime on Client side
- Add settings on Client side to select TimeZone, then do some math Azure DateTime offset by selected TimeZone. If this solution, in which format should I create a list of time zones and how to perform calculations? My TimeStamp in UTC in DateTime format ?
- Retrieve clients time automatically, I have seen there are some JavaScript solutions available that are capable to get user browser time. For example:
Note:
Here you might encounter one issue, if your server time is not same as your local time in that case time conversion may not be as expected. So if that is the case you could have a try below way:Convert Azure Time To Any Standard Time:
This the way you could convert
UTC
time to anystandard time zone
. Here is the example:var azureTime = "18-Apr-22 5:21:29 AM"; // Getting Time From Azure var convertedAzureTime = Convert.ToDateTime(azureTime); // Because I have save date time as string TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); DateTime yourLocalTime = TimeZoneInfo.ConvertTimeFromUtc(convertedAzureTime, cstZone); Console.WriteLine("Azure Time {0}",convertedAzureTime); Console.WriteLine("Converted Local Time {0}",yourLocalTime);
Note:
You can convert in anytime zone you want by usingHope above explanation and example would be guided you accordingly