How can I tell if a string is a Hebrew or Gregorian date?

I have a string value that contains either a Hebrew date or a Gregorian date. How can I tell if it is in Gregorian or Hebrew in C #?

+2


a source to share


1 answer


You can use the TryParse

object method DateTime

- if it fails with Hebrew culture, you can try the Gregorian calendar:



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
}

      

+6


a source







All Articles