I am in the process of customizing a SharePoint master page by adding a unique header that showcases the current time across four different time zones. However, I am faced with the challenge of determining the appropriate server-side time to use for accurate calculations, as relying on client-side time can lead to discrepancies due to varying time zones and incorrect system settings.
The desired display format for the time zones is as follows:
Dallas: (UTC-6 with DST support) Zulu: (UTC) Iraq: (UTC+3) Afghanistan: (UTC+4.5)
My main issue stems from my limited knowledge of ASP.NET, coming from a PHP background. I require a method to pass the serverTime variable to JavaScript for dynamic calculations to cater to each specific time zone.
UPDATE:
The goal is to have the clock update in real-time, reflecting every second change rather than displaying a static time.
UPDATE 2:
Provided below is the code snippet I am currently utilizing, any recommendations are appreciated:
<script runat="server">
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
End Sub
Public Function dtBase() As Double
Dim d1 As Date = New Date(1970, 1, 1)
Dim d2 As Date = Date.UtcNow
Dim ts As TimeSpan = d2 - d1
Return ts.TotalMilliseconds
End Function
</script>
<html>
<head>
<script type="text/javascript">
// JavaScript functions for displaying and updating multiple time zones
// Code shortened for brevity...
</script>
</head>
<body onload="zuluT();dallasT();iraqT();afgnT();">
<table>
<tr>
<td>
DALLAS: <span id="DALLAS"> </span>
ZULU: <span id="ZULU"> </span>
IRAQ: <span id="IRAQ"> </span>
AFGN: <span id="AFGN"> </span>
</td>
</tr>
</table>
UPDATE 3:
Despite encountering issues with implementing the code due to restrictions set by the SharePoint server, further modifications were made to ensure its functionality. For future readers facing similar challenges, it's important to enable server-side scripting by modifying the web.config file. Detailed instructions are provided below:
<PageParserPath VirtualPath="/relative/path/to/your/file/here.aspx" CompilationMode="Always" AllowServerSideScript="true" />
Your feedback is greatly valued. Thank you.