Persian DateTime

public static string ToPersianDate(this DateTime? dt)
        {
            try
            {
                var dateTime = dt.ToDateTime();
                PersianCalendar persianCalendar = new PersianCalendar();
                string year = persianCalendar.GetYear(dateTime).ToString();
                string month = persianCalendar.GetMonth(dateTime).ToString()
                               .PadLeft(2, '0');
                string day = persianCalendar.GetDayOfMonth(dateTime).ToString()
                               .PadLeft(2, '0');
                string hour = dateTime.Hour.ToString().PadLeft(2, '0');
                string minute = dateTime.Minute.ToString().PadLeft(2, '0');
                string second = dateTime.Second.ToString().PadLeft(2, '0');
                return String.Format("{0}/{1}/{2} {3}:{4}:{5}", year, month, day, hour, minute, second);

            }
            catch
            {

                throw;
            }
        }
Example:
var persianDate=DateTime.Now().ToPersionDate();

Description

Convert DateTime To PersianDate

Details

Double click on the code to select all.

 

;