ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Set TimeZone in AJAX CalendarExtender using C# and VB.Net in ASP.Net<p>Hi&nbsp;<a class="username" rel="nauna">nauna,</a></p> <p>Refer below sample.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34;&gt; function clientShowing(sender, args) { sender.set_todaysDate(new Date(&#39;&lt;%= ToCalenderFormat(GetDatetimewithtimezone(&#34;MOUNTAIN STANDARD TIME&#34;),GetTimeSpanDifference(&#34;MOUNTAIN STANDARD TIME&#34;)) %&gt;&#39;)); sender.set_startDate(&#39;&lt;%= ToCalenderFormat(GetDatetimewithtimezone(&#34;MOUNTAIN STANDARD TIME&#34;),GetTimeSpanDifference(&#34;MOUNTAIN STANDARD TIME&#34;)) %&gt;&#39;); sender.set_endDate(&#39;&lt;%= ToCalenderFormat(GetDatetimewithtimezone(&#34;MOUNTAIN STANDARD TIME&#34;).AddDays(7),GetTimeSpanDifference(&#34;MOUNTAIN STANDARD TIME&#34;)) %&gt;&#39;); } &lt;/script&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34; /&gt; &lt;asp:Label ID=&#34;lblb&#34; runat=&#34;server&#34;&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID=&#34;txtDate&#34; runat=&#34;server&#34; CssClass=&#34;disable_future_dates&#34; /&gt; &lt;asp:ImageButton runat=&#34;server&#34; ID=&#34;imgPopup&#34; ImageUrl=&#34;~/Calendar.png&#34; /&gt; &lt;cc1:CalendarExtender ID=&#34;CalendarExtender1&#34; runat=&#34;server&#34; TargetControlID=&#34;txtDate&#34; PopupButtonID=&#34;imgPopup&#34; OnClientShowing=&#34;clientShowing&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">public static String ToCalenderFormat(DateTime dt, TimeSpan TimeZoneDifference) { return new DateTimeOffset(dt.Ticks, TimeZoneDifference).ToString(&#34;yyyy-MM-ddTHH:mm:ssZ&#34;); } public static DateTime GetDatetimewithtimezone(string Timezone) { return (TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(Timezone))); } public static TimeSpan GetTimeSpanDifference(string Timezone) { TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(Timezone); return timeZoneInfo.BaseUtcOffset; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Public Shared Function ToCalenderFormat(ByVal dt As DateTime, ByVal TimeZoneDifference As TimeSpan) As String Return New DateTimeOffset(dt.Ticks, TimeZoneDifference).ToString(&#34;yyyy-MM-ddTHH:mm:ssZ&#34;) End Function Public Shared Function GetDatetimewithtimezone(ByVal Timezone As String) As DateTime Return (TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(Timezone))) End Function Public Shared Function GetTimeSpanDifference(ByVal Timezone As String) As TimeSpan Dim timeZoneInfo As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(Timezone) Return timeZoneInfo.BaseUtcOffset End Function</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/vUSvBqB.jpg" alt="" width="238" height="336" /></span></strong></p>https://www.aspforums.net:443/Threads/140921/Set-TimeZone-in-AJAX-CalendarExtender-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/140921/Set-TimeZone-in-AJAX-CalendarExtender-using-C-and-VBNet-in-ASPNet/Mon, 17 Dec 2018 05:30:47 GMT