Show date with time in PersianCalendar format in C#

Last Reply on Oct 24, 2016 06:02 AM By AnandM

Posted on Oct 24, 2016 01:49 AM

hi

I used below code to change date to shamsi type (persian date)

    public string miladitoshamsi(object miladi1)
    {
        DateTime miladi = Convert.ToDateTime(miladi1);
        System.Globalization.PersianCalendar shamsi = new System.Globalization.PersianCalendar();
        return string.Format("{0}/{1}/{2}", shamsi.GetYear(miladi), shamsi.GetMonth(miladi), shamsi.GetDayOfMonth(miladi));

    }

but it just show date I want it shows date with time from database:

in database I save date and time in table

Date  datetime

Posted on Oct 24, 2016 05:42 AM Modified on on Oct 24, 2016 06:02 AM

Hi nedash,

Replace your code with below 

public string miladitoshamsi(object miladi1)
{
    DateTime miladi = Convert.ToDateTime(miladi1);
    System.Globalization.PersianCalendar shamsi = new System.Globalization.PersianCalendar();
    return string.Format("{0}/{1}/{2} {3}:{4}:{5}.{6}", shamsi.GetYear(miladi), shamsi.GetMonth(miladi), shamsi.GetDayOfMonth(miladi), shamsi.GetHour(miladi), shamsi.GetMinute(miladi), shamsi.GetSecond(miladi), shamsi.GetMilliseconds(miladi));
}