ToDateTime() public method

Returns a DateTime that is set to the specified Date and time in the specified era.
public ToDateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, int era ) : System.DateTime
year int An integer that represents the year.
month int An integer that represents the month.
day int An integer that represents the day.
hour int An integer that represents the hour.
minute int An integer that represents the minute.
second int An integer that represents the second.
millisecond int An integer that represents the millisecond.
era int An integer that represents the era.
return System.DateTime
Exemplo n.º 1
0
        public static string GetTermStart(int TermNo)
        {
            string strDateSource = System.IO.File.ReadAllText(Application.StartupPath + "\\DateSource.txt");

            TermNo -= 10;
            if (TermNo == 0)
            {
                return(strDateSource);
            }
            int             DateSourceYear  = Convert.ToInt16("13" + strDateSource.Substring(0, 2));
            int             DateSourceMonth = Convert.ToInt16(strDateSource.Substring(3, 2));
            int             DateSourceDay   = Convert.ToInt16(strDateSource.Substring(6, 2));
            PersianCalendar pc = new FarsiLibrary.Utils.PersianCalendar();
            DateTime        dt = pc.ToDateTime(DateSourceYear, DateSourceMonth, DateSourceDay, 1, 1, 1, 1);

            dt = dt.AddMonths(2 * (TermNo - 1));
            PersianDate pd        = PersianDateConverter.ToPersianDate(dt);
            int         daysToAdd = 0;

            if (pd.Day > 15)
            {
                daysToAdd = 1;
            }
            else if (pd.Day < 15)
            {
                daysToAdd = -1;
            }
            while (pd.Day != 1)
            {
                dt = dt.AddDays(daysToAdd);
                pd = PersianDateConverter.ToPersianDate(dt);
            }
            string year  = pd.Year.ToString();
            string month = pd.Month.ToString();
            string day   = pd.Day.ToString();

            if (month.Length == 1)
            {
                month = "0" + month;
            }
            if (day.Length == 1)
            {
                day = "0" + day;
            }
            return((year + "/" + month + "/" + day).Remove(0, 2));
        }
        private DateTime GetToDate()
        {
            int year = Convert.ToInt32(cmbYear.SelectedItem);
            int month = Convert.ToInt32(cmbMonth.SelectedIndex) + 1;

            int day = 30;
            if (month < 7)
                day = 31;
            else if (month == 12 && !(((year - 1391) % 4) == 0))
                day = 29;

            PersianCalendar pc = new PersianCalendar();

            return pc.ToDateTime(year, month, day, 0, 0, 0, 0);
        }
        private DateTime GetFromDate()
        {
            int year = Convert.ToInt32(cmbYear.SelectedItem);
            int month = Convert.ToInt32(cmbMonth.SelectedIndex) + 1;

            PersianCalendar pc = new PersianCalendar();

            return pc.ToDateTime(year, month, 1, 0, 0, 0, 0);
        }
 public void ToDateTime_With_Invalid_Day_Throws()
 {
     Assert.Throws <InvalidPersianDateException>(() => calendar.ToDateTime(1384, 1, 32, 0, 0, 0, 0));
     Assert.Throws <InvalidPersianDateException>(() => calendar.ToDateTime(1384, 0, 0, 0, 0, 0, 0));
     Assert.Throws <InvalidPersianDateException>(() => calendar.ToDateTime(1384, 1, 0, 0, 0, 0, 0));
 }