[英]How can I get today's Jewish date in c#?
我有這個代碼:
DateTime dtAnyDateHebrew = new DateTime(5767, 1, 1, new System.Globalization.HebrewCalendar());
如何獲得今天的數字希伯來日期?
意義:
例如,我想知道本月是否有特定的希伯來月份,所以我必須將希伯來月份發送到 function - 帶有今天的月份和年份,這樣我就可以檢查 dtAnyDateHebrew 是否相等到今天,比。 等等
最后我需要得到 - 今天的希伯來日期,今天的希伯來月份,今天的希伯來年份,作為 int (當然)。
有人能幫我嗎?
好吧,我找到了我需要的東西:
DateTime Today = DateTime.Today;
Calendar HebCal = new HebrewCalendar();
int curYear = HebCal.GetYear(Today); //current numeric hebrew year
int curMonth = HebCal.GetMonth(Today); //current numeric hebrew month
etc..
就是這么簡單。
感謝大家。
使用DateTime.Today
並使用以下前之一對其進行轉換。 方法:
/// <summary>
/// Converts a gregorian date to its hebrew date string representation,
/// using custom DateTime format string.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> value to convert.</param>
/// <param name="format">A standard or custom date-time format string.</param>
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);
}
/// <summary>
/// Converts a gregorian date to its hebrew date string representation,
/// using DateTime format options.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> value to convert.</param>
/// <param name="dayOfWeek">Specifies whether the return string should
/// include the day of week.</param>
public static string ToJewishDateString(this DateTime value, bool dayOfWeek)
{
var format = dayOfWeek ? "D" : "d";
return value.ToJewishDateString(format);
}
此博客條目顯示了如何。
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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.