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 02:00 AM

Hi nedash,

can you tell how your date time is getting saved in database i.e Format of saving.For eg (2016/05/10 15:25:15) some kind.


Posted on Oct 24, 2016 05:18 AM
hi anandM it is like: 2016-10-22 20:18:04.350

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));
}

 


Posted on Oct 24, 2016 05:55 AM

this error happen

Server Error in '/' Application.


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0161: 'Admin_NewOrder.miladitoshamsi(object)': not all code paths return a value

Source Error: