文字列がヘブライ語かグレゴリオの日付かを判断するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/2798208

質問

私には、ヘブライ語の日付を含む文字列値、またはグレゴリオの日付があります。 C#のグレゴリオまたはヘブライ語かどうかをどのように判断できますか?

役に立ちましたか?

解決

使用できます TryParse の方法 DateTime オブジェクト - ヘブライ文化で失敗した場合、グレゴリオカレンダーで試すことができます。

DateTime myDate = DateTime.Now;
CultureInfo culture = CultureInfo.CreateSpecificCulture("he-IL");
culture.DateTimeFormat.Calendar = new HebrewCalendar(); // To be sure
DateTimeStyles styles = DateTimeStyles.None;

if (DateTime.TryParse("כ\"ה/אייר/תש\"ע", culture, styles, out myDate))
{
   // Hebrew date
}

culture = CultureInfo.CreateSpecificCulture("en-US");

if (DateTime.TryParse("2/30/2010", culture, styles, out myDate))
{
   // US date
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top