15

私はこのコードを持っています:

DateTime dtAnyDateHebrew = new DateTime(5767, 1, 1, new System.Globalization.HebrewCalendar());

今日の数値ヘブライ日付を取得するにはどうすればよいですか?

意味:

たとえば、特定のヘブライ語の月が今月に該当するかどうかを調べたいので、dtAnyDateHebrew が等しいかどうかを確認できるように、ヘブライ語の月を関数に送信する必要があります。今日まで、より大きい。等

最後に取得する必要があります - 今日のヘブライ語の日、今日のヘブライ語の月、今日のヘブライ語の年 (もちろん int)。

誰かが私を助けることができますか?

4

3 に答える 3

10

さて、私は必要なものを見つけました:

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..

それはとても簡単です。

皆さんのお陰で。

于 2011-06-09T07:45:18.697 に答える
9

次の例のいずれかを使用して使用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);
}
于 2012-01-18T20:15:05.640 に答える
3

このブログエントリはその方法を示しています。

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(); 
}
于 2011-06-05T20:13:15.097 に答える