Installation and deployment
Version 7.x > Installation and deployment > changing datetime to shamsi (Persian datetime) View modes: 
User avatar
Member
Member
Iman - 2/7/2014 6:00:01 AM
   
changing datetime to shamsi (Persian datetime)
Hi,
How can i change the whole of kentico 7 cms datetime to Persian datetime?
I want to set shamsi date in both CurrentCulture and CurrentUICulture when the culture is "fa-IR".

Thanks for your help.

User avatar
Member
Member
kentico_davidb2 - 2/7/2014 7:14:56 AM
   
RE:changing datetime to shamsi (Persian datetime)
CurrentCulture reflects the currently selected content culture.
CurrentUICulture reflects the UI culture.

If you want to have everything in this culture, I would recommend adding the culture to Site manager -> Development -> UI cultures, then in Site manager -> Sites -> your_site -> Cultures add your culture as well. And finally, Select your culture for Default content culture and Visitor culture in Site manager -> Sites -> your_site -> General. Also, you can set your culture default in Site manager -> Settings -> Content -> Multilingual -> Default content culture globally. For the default UI culture, you need to do the following:

Yes, there is a web.config key CMSDefaultUICulture, which specifies the default UI culture. If you use this key, you also need to rename the ~\CMSResources\CMS.resx file to CMS.en-us.resx and the CMS.fa-ir.resx file to CMS.resx. This is needed because the CMS.resx file is used when the (default) option is selected in users' Preferred user interface culture.

The default value is en-us and you can change it like this:

<add key="CMSDefaultUICulture" value="fa-ir"/>

Most of these are summarized in:
http://devnet.kentico.com/FAQs/Multilingual-support/How-can-I-change-the-date-format-.aspx

User avatar
Member
Member
Iman - 2/7/2014 2:05:48 PM
   
RE:changing datetime to shamsi (Persian datetime)
I know that i can change the content culture and UI Culture in Site manager but i want to show Shamsi(Jalali) datetime instead of the Gregorian datetime like this:

Shamsi datetime: 1392/11/17 6:00:00 ق.ظ

Gregorian datetime: 2/7/2014 6:00:00 AM

Shamsi date format is not natively supported by the .Net framework and I want to fix Persian Culture for Persian Calendar based on these articles:
How to Set PersianCalendar to CultureInfo
Using Custom Culture Approach to Fix Persian Culture for Persian Calendar

User avatar
Member
Member
kentico_davidb2 - 2/7/2014 10:34:36 PM
   
RE:changing datetime to shamsi (Persian datetime)
Well, Kentico does officially only support what .NET framework supports, but have you tried installing the mentioned package to your webserver?

As it mentions in its description, it should then behave correctly when using standard DateTime classes.

What issues have you run into?

User avatar
Member
Member
Iman - 2/8/2014 12:53:11 AM
   
RE:changing datetime to shamsi (Persian datetime)
OK, I can not install mentioned package in a shared host.
My solution is to call a static method to fix it:
http://www.codeproject.com/Articles/250740/Fixing-Optional-Calendars-for-Persian-Culture-in-N

But where can I use "FixAndSetCurrentCulture()" method based on mentioned article every time the content Culture and UI Culture change to "fa-ir"?

Can I change Culture of whole Kentico CMS based on these two lines code and where:
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;


/// <summary>
/// Set the CurrentCulture of current thread to a new fixed Persian culture.
/// </summary>
/// <returns>The fixed Persian cultreinfo.</returns>
public static CultureInfo FixAndSetCurrentCulture()
{
CultureInfo culture = FixPersianCulture(null,FixCultureOptions.foptAll);
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
return culture;
}

/// <summary>
/// Fixes CultureInfo for Persian resources (months and day names) and also PersianCalendar.
/// </summary>
/// <param name="culture">The CultureInfo instace to be fixed. If NULL, a new instance will be created and returned.</param>
/// <param name="options">Specifies what to be fixed.</param>
/// <returns>A new instance of fixed Persian CultureInfo.</returns>
public static CultureInfo FixPersianCulture(CultureInfo culture, FixCultureOptions options)
{
PropertyInfo calendarID = typeof(Calendar).GetProperty("ID", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo cultureInfoReadOnly = typeof(CultureInfo).GetField("m_isReadOnly", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
FieldInfo cultureInfoCalendar = typeof(CultureInfo).GetField("calendar", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
//FieldInfo cultureInfoReadOnly = typeof(CultureInfo).GetField("m_", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
if (culture == null)
culture = new CultureInfo("fa-IR", false);
if (culture == null || culture.LCID != 1065)
return culture;
if ((options & FixCultureOptions.foptAll) == FixCultureOptions.foptAll)
options = FixCultureOptions.foptCalendarInCulture | FixCultureOptions.foptCalendarInDateFormatInfo |
FixCultureOptions.foptOptionalCalendars;
if ((options & FixCultureOptions.foptOptionalCalendars) == FixCultureOptions.foptOptionalCalendars)
{
FixOptionalCalendars(culture, 4);
culture = new CultureInfo("fa-IR", false);
}

bool readOnly = (bool)cultureInfoReadOnly.GetValue(culture);
if (readOnly)
{
cultureInfoReadOnly.SetValue(culture, false);
}
if ((options & FixCultureOptions.foptCalendarInDateFormatInfo) == FixCultureOptions.foptCalendarInDateFormatInfo)
culture.DateTimeFormat = FixPersianDateTimeFormat(culture.DateTimeFormat, true);
else
FixPersianDateTimeFormat(culture.DateTimeFormat, false);
if ((options & FixCultureOptions.foptCalendarInCulture )
== FixCultureOptions.foptCalendarInCulture)
{
cultureInfoCalendar.SetValue(culture, new PersianCalendar());
}
if (readOnly)
{
cultureInfoReadOnly.SetValue(culture, true);
}
return culture;
}

User avatar
Member
Member
caspian_softdev-yahoo - 2/16/2014 2:07:09 AM
   
RE:changing datetime to shamsi (Persian datetime)
HI
Iman you must buy complete code to do that.

second way for display Persian date in your content you need to write your own convert function

third way having macro could be a good solution.


User avatar
Member
Member
Iman - 3/22/2014 3:42:22 AM
   
RE:changing datetime to shamsi (Persian datetime)
None of the respondents were not able to help me. So much effort, I was able to find a solution to this issue.

Thanks a lot