All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:
Posted 08 Oct 2018 Link to this post
This applies to all Telerik UI for ASP.NET AJAX calendars and date/time pickers.
All of these controls support Gergorian calendars only and so various other calendars (like the Buddhist or Hijri) may cause issues like date displacement.
For example, the Thailand calendar uses a Buddhist year which is offset from the Gregorian calendar by 543 years. So, for this particular culture an easy workaround would be to subtract those years:
<
telerik:RadDatePicker
runat
=
"server"
ID
"rdp1"
>
</
asp:Button
Text
"get date on server"
"btn1"
OnClick
"btn1_Click"
/>
protected
override
void
InitializeCulture()
{
//set Thai culture to the page
System.Threading.Thread.CurrentThread.CurrentCulture =
new
System.Globalization.CultureInfo(
"th-TH"
);
}
btn1_Click(
object
sender, EventArgs e)
DateTime? selDate = rdp1.SelectedDate;
if
(System.Threading.Thread.CurrentThread.CurrentCulture.Name ==
&& selDate.HasValue)
//subtract the year difference from the dates
DateTime targetTime = selDate.GetValueOrDefault().AddYears(-543);
Response.Write(targetTime);
//always use Gregorian calendar
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.Calendar =
System.Globalization.GregorianCalendar();
You can also find an alternative approach that creates new CultureInfo classes with a Gregorian calendar based on the current culture in the following code library: How to set up r.a.d.datepicker with cultures that use default Hijri Calendar.
NOTE: Telerik cannot guarantee these workaround will produce the desired effect, nor how they can scale across multiple cultures and calendars.
Posted 10 Oct 2018 Link to this post
The .GetYear() and other methods of the .NET Calendar instance seem to be able to convert between calendars. Here is a small test you can try as well.
Page_Load(
//this is something similar to what happens when the date is parsed after the POST
DateTime startYear =
DateTime(2000, 11, 22,
System.Globalization.ThaiBuddhistCalendar());
//so such a conversion should be OK, as long as .NET does it well, I could not find proper documentation that confirms
//that it is supposed to work, even though it seems to, and so I am not in a position to guarantee this approach is safe
System.Globalization.Calendar gregCal =
Response.Write(gregCal.GetYear(startYear));
which prints out 1457 as expected.
//this is even more similar to what happens when the date is parsed after the POST
DateTime(2000, 11, 22, System.Threading.Thread.CurrentThread.CurrentCulture.Calendar);
Posted 11 Oct 2018 in reply to D41B02FE-0EF9-48A6-9B2C-E910424294F5 Link to this post
I would like to add a web page and code behind that describes how to do this. I've posted the Default.aspx and Default.aspx.cs files. You will need to supply the rest of the solution and try it out.
Posted 11 Oct 2018 Link to this post
The conversion methods at the end (ConvertToDBDate called from txtRequiredDeliveryDate_SelectedDateChanged) is at the end for those who are only looking for a conversion approach.
--Marin
This Code Library is part of the product documentation and subject to the respective product license agreement.