コード例 #1
0
        public PersianDateTime(string shamsiDate = "1380/01/01 23:32:56")
        {
            if (!PersianHelper.IsPersianDateValid(shamsiDate.Replace(" ", "").Substring(0, 10)))
            {
                throw new ArgumentOutOfRangeException("فرمت تاریخ وارد شده صحیح نمی باشد");
            }

            if (shamsiDate.Length > 10)
            {
                if (PersianHelper.IsTimeValid(shamsiDate.Substring(11, shamsiDate.Length - 11)))
                {
                    int h = 0, m = 0, s = 0;
                    if (shamsiDate.Length > 11)
                    {
                        int.TryParse(shamsiDate.Substring(11, 2), out h);
                    }
                    if (shamsiDate.Length > 14)
                    {
                        int.TryParse(shamsiDate.Substring(14, 2), out m);
                    }
                    if (shamsiDate.Length > 17)
                    {
                        int.TryParse(shamsiDate.Substring(17, 2), out s);
                    }
                    Hour   = h;
                    Minute = m;
                    Second = s;
                }
            }
            Year     = Convert.ToInt32(shamsiDate.Substring(0, 4));
            Month    = Convert.ToInt32(shamsiDate.Substring(5, 2));
            Day      = Convert.ToInt32(shamsiDate.Substring(8, 2));
            DateTime = persianCalendar.ToDateTime(Year, Month, Day, Hour, Minute, Second, Millisecond);
        }
コード例 #2
0
        public PersianDateTime(string shamsiDate = "1380/01/01 23:32:56")
        {
            this.Year          = this.Month = this.Day = this.Hour = this.Minute = this.Second = this.Millisecond = 0; this.HijriDate = new HijriDate();
            this.DateMetaDatas = null; this.IsHoliDay = false; this.dateTime = DateTime.Now;
            if (!PersianHelper.IsPersianDateValid(shamsiDate.Replace(" ", "").Substring(0, 10)))
            {
                throw new ArgumentOutOfRangeException("فرمت تاریخ وارد شده صحیح نمی باشد");
            }
            if (shamsiDate.Length > 10)
            {
                if (PersianHelper.IsTimeValid(shamsiDate.Substring(11, shamsiDate.Length - 11)))
                {
                    int h = 0, m = 0, s = 0;
                    if (shamsiDate.Length > 11)
                    {
                        int.TryParse(shamsiDate.Substring(11, 2), out h);
                    }
                    if (shamsiDate.Length > 14)
                    {
                        int.TryParse(shamsiDate.Substring(14, 2), out m);
                    }
                    if (shamsiDate.Length > 17)
                    {
                        int.TryParse(shamsiDate.Substring(17, 2), out s);
                    }
                    this.Hour   = h;
                    this.Minute = m;
                    this.Second = s;
                }
            }
            this.Year  = Convert.ToInt32(shamsiDate.Substring(0, 4));
            this.Month = Convert.ToInt32(shamsiDate.Substring(5, 2));
            this.Day   = Convert.ToInt32(shamsiDate.Substring(8, 2));

            this.dateTime = persianCalendar.ToDateTime(this.Year, this.Month, this.Day, this.Hour, this.Minute, this.Second, this.Millisecond);
            this.CommonConstructor(this.dateTime);
        }