示例#1
0
        private void calculateDate()
        {
            DateTime datestart = DateTime.Now;


            string finishFa = maskedTextBox1.Text;

            if (finishFa == null || finishFa == "")
            {
                finishFa = "1397/5/29";
            }
            //string to FaDateTime
            FaDateTime faDate    = new  FaDateTime();
            FaDate     dateFarsi = faDate.getFaDateTime(finishFa);

            if (dateFarsi.day > faDate.getthisMonthsDay())
            {
                MessageBox.Show("خطا روز بزرگتر از روز های ماه است");
                return;
            }
            if ((dateFarsi.month < dateFarsi.thisMonth && dateFarsi.year < dateFarsi.thisYear) || (dateFarsi.year < dateFarsi.thisYear))
            {
                MessageBox.Show("خطا  سال یا ماه کوچکتر از مقدار معین است");
                return;
            }
            try {
                DateTime finishTime = ConvertDate.ToEn(finishFa);
                TimeSpan difference = finishTime - datestart;

                int days      = dateFarsi.toEndMonth;
                int daystoend = dateFarsi.toEndMonth;
                if (daystoend >= faDate.getthisMonthsDay())
                {
                    daystoend = daystoend - faDate.getthisMonthsDay();
                    this.month++;
                }
                s = difference.Seconds;
                m = difference.Minutes;
                h = difference.Hours;

                this.month = ((finishTime.Year - datestart.Year) * 12) + finishTime.Month - datestart.Month;;
                this.d     = daystoend;
            }
            catch (Exception ex)
            {
            }
        }
示例#2
0
        public FaDate getFaDateTime(string FaDate)
        {
            FaDate date = new FaDate();

            try {
                string[] finishFaArray = FaDate.Split('/');

                date.year  = Convert.ToInt32(finishFaArray[0]);
                date.month = Convert.ToInt32(finishFaArray[1]);
                date.day   = Convert.ToInt32(finishFaArray[2]);


                var persianCal = new System.Globalization.PersianCalendar();
                date.monthsDay = persianCal.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                date.today     = persianCal.GetDayOfMonth(DateTime.Now);
                date.thisMonth = persianCal.GetMonth(DateTime.Now);
                date.thisYear  = persianCal.GetYear(DateTime.Now);
                if (date.year == persianCal.GetYear(DateTime.Now) && date.month == persianCal.GetMonth(DateTime.Now))
                {
                    date.toEndMonth = date.day - date.today;
                }
                else
                {
                    date.today      = persianCal.GetDayOfMonth(DateTime.Now);
                    date.toEndMonth = date.monthsDay - date.today + date.day;
                }

                return(date);
            }
            catch (Exception ex)
            {
                date.year      = 0;
                date.month     = 0;
                date.day       = 0;
                date.monthsDay = 0;
                return(date);
            }
        }