public static PersianDateTime Parse(string s)
        {
            PersianDateTime pdate = null;

            try
            {
                var d = s.Split('/');
                if (d.Length != 3)
                {
                    throw new FormatException("String was not recognized as a valid PersianDateTime.");
                }
                int year = Convert.ToInt32(d[0]), month = Convert.ToInt32(d[1]), day = Convert.ToInt32(d[2].Split(' ')[0]);
                //int hour = 12, minute = 0, second = 0, millisecond = 0;
                //d = s.Split(' ');
                //if (d.Length > 2) {
                //    d = d[1]
                //}
                var cc = new PersianCalendar();

                pdate = new PersianDateTime(cc.ToDateTime(year, month, day, 12, 0, 0, 0));
            }
            catch
            {
                throw new Exception("تاريخ نا معتبر مي باشد.");
            }
            return(pdate);
        }
 public static bool TryParse(string s, out PersianDateTime result)
 {
     try
     {
         string[] d = s.Split('/');
         if (d.Length != 3)
         {
             result = null;
             return(false);
         }
         int             year = Convert.ToInt32(d[0]), month = Convert.ToInt32(d[1]), day = Convert.ToInt32(d[2]);
         PersianCalendar cc = new PersianCalendar();
         result = new PersianDateTime(cc.ToDateTime(year, month, day, 12, 0, 0, 0));
     }
     catch
     {
         result = null;
         return(false);
     }
     return(true);
 }
 public TimeSpan Subtract(PersianDateTime value)
 {
     return(ToDateTime().Subtract(ToDateTime(value)));
 }
 public static bool Equals(PersianDateTime d1, PersianDateTime d2)
 {
     return(DateTime.Equals(ToDateTime(d1), ToDateTime(d2)));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool Equals(PersianDateTime value)
 {
     return(ToDateTime().Equals(ToDateTime(value)));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public int CompareTo(PersianDateTime value)
 {
     return(ToDateTime().CompareTo(ToDateTime(value)));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="d1"></param>
 /// <param name="d2"></param>
 /// <returns></returns>
 public static int Compare(PersianDateTime d1, PersianDateTime d2)
 {
     return(DateTime.Compare(ToDateTime(d1), ToDateTime(d2)));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(PersianDateTime date)
        {
            var cc = new PersianCalendar();

            return(cc.ToDateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Millisecond));
        }