I am coding a MVC 5 internet application that is being deployed to an Azure website. This application is going to be used internationally, and I am wanting to know if storing any DateTime values should use UTC time?
Here is an example: I have an object that has a start date time value as well as an end date time value. These values are set by a user and are used to determine if data should be shown to a user. If the current date time value is between the start date time and end date time, then data is shown.
Because my application is going to be used internationally, and there are different time zones, should I store the start date time value and end date time value as a DateTime object with UTC, or a standard DateTime value would be all that is needed? Do I need to worry about setting and displaying DateTime values for different time zones, or is this incorporated into the DateTime object?
Thanks in advance.
EDIT
How about when editing a DateTime that is stored as UTC.
If I have a DateTime that is stored as UTC in an object, and the user wants to change this value, do I need to convert the DateTime (that is displayed as .ToLocalTime()) back to a UTC DateTime when I store this value back in the database after it has been edited?
EDIT2
Can you have a quick look at these functions that I have coded to ensure the coding is correct?
public DateTime ConvertUTCDateTimeToLocalTime(DateTime utcDateTime)
{
DateTime convertedDate = DateTime.SpecifyKind(utcDateTime, DateTimeKind.Utc);
return convertedDate.ToLocalTime();
}
public DateTime ConvertLocalDateTimeToUniversalTime(DateTime localDateTime)
{
DateTime convertedDate = DateTime.SpecifyKind(localDateTime, DateTimeKind.Local);
return convertedDate.ToUniversalTime();
}
public DateTime ConvertUTCDateTimeToLocalTime(string utcDateTime)
{
DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(utcDateTime.ToString()), DateTimeKind.Utc);
return convertedDate.ToLocalTime();
}
public DateTime ConvertLocalDateTimeToUniversalTime(string localDateTime)
{
DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(localDateTime.ToString()), DateTimeKind.Local);
return convertedDate.ToUniversalTime();
}