public static string GetHebrewJewishDateString(DateTime anyDate, bool addDayOfWeek)
{
System.Text.StringBuilder hebrewFormatedString = new System.Text.StringBuilder();
// Create the hebrew culture to use hebrew (Jewish) calendar
CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
jewishCulture.DateTimeFormat.Calendar = new HebrewCalendar();
#region Format the date into a Jewish format
if (addDayOfWeek)
{
// Day of the week in the format " "
hebrewFormatedString.Append(anyDate.ToString("dddd", jewishCulture) + " ");
}
// Day of the month in the format "'"
hebrewFormatedString.Append(anyDate.ToString("dd", jewishCulture) + " ");
// Month and year in the format " "
hebrewFormatedString.Append("" + anyDate.ToString("y", jewishCulture));
#endregion
return hebrewFormatedString.ToString();
}
5 comments:
Thanks
Eliezer, Israel
www.koltuv.org לזיכוי הרבים בספרי קודש
thank you very much!!!!
תודה רבה!
A grat and genius solution!
Thanks!
HaVer
Replace your code with:
public static string ToJewishDateString(this DateTime value, string format)
{
var ci = CultureInfo.CreateSpecificCulture("he-IL");
ci.DateTimeFormat.Calendar = new HebrewCalendar();
return value.ToString(format, ci);
}
public static string ToJewishDateString(this DateTime value, bool dayOfWeek)
{
var format = dayOfWeek ? "D" : "d";
return value.ToJewishDateString(format);
}
To be more string-format flexible.
תודה רבה!
Thank you very much!!! :)
Post a Comment