Hi @Donald Symmons,
can you please show in a nutshell and in an understandable way how to convert Date and Time to local Date and Time and display it in a label control on the Web page?
Your code can only be implemented by the button, not in Page_Load, because the server-side code executes first, then the client-side code.
You can simply convert time from one time zone to another.
You can find specific information in the documentation.
ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)
DateTime:The date and time to convert.
sourceTimeZone TimeZoneInfo:The time zone of dateTime
.
destinationTimeZone TimeZoneInfo:The time zone to convert dateTime
to.
You can also specify the time zone directly, for example:
TimeZoneInfo serverTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Arabic Standard Time");
Microsoft Time Zone Index Values
protected void Page_Load(object sender, EventArgs e)
{
TimeZoneInfo serverTimeZone = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneInfo.Local.Id); // Get Server TimeZone
DateTime time = new DateTime(2019, 08, 21, 11, 59, 59);
DateTime dateTime = TimeZoneInfo.ConvertTime(time, serverTimeZone, TimeZoneInfo.Local); // Convert to local time
Label1.Text = dateTime.ToString();
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.