How to convert a Persian date into a Gregorian date?

前端 未结 9 1287
萌比男神i
萌比男神i 2020-12-30 04:30

I use the function below to convert Gregorian dates to Persian dates, but I\'ve been unable to write a function to do the reverse conversion. I want a function that converts

9条回答
  •  梦谈多话
    2020-12-30 05:28

    This method converts a string which represents a shamsi date to System.DateTime :

        public DateTime milady(string shamsiDate)
        {
            DateTime dt = new DateTime();
            PersianCalendar pc = new PersianCalendar();
    
            int pYear = Convert.ToInt32(shamsiDate.Substring(0, 4));
            int pMonth =Convert.ToInt32(shamsiDate.Substring(5, 2));
            int pDay =  Convert.ToInt32( shamsiDate.Substring(8));
    
    
            dt = pc.ToDateTime(pYear, pMonth, pDay,0,0,0,0);
            return dt;
        }
    

提交回复
热议问题