我需要将转换日期转换为shamsi日期
我创建了一个将DateTime转换为shamsi Date的方法。
当我将日期传递给方法时出现此错误
'BentaAccounting.Classes.GenralClasses.FarsiDate.MiladiToShamsi(System.DateTime)'的最佳重载方法匹配有一些无效的参数
这是我正在使用的代码
方法
public static string MiladiToShamsi(DateTime Date)
{
string Result;
PersianCalendar FarsiDate = new PersianCalendar();
Result = FarsiDate.GetYear(Date).ToString() + "/" +
(FarsiDate.GetMonth(Date) < 10 ? "0" + FarsiDate.GetMonth(Date).ToString() : FarsiDate.GetMonth(Date).ToString()) + "/" +
(FarsiDate.GetDayOfMonth(Date) < 10 ? "0" + FarsiDate.GetDayOfMonth(Date).ToString() : FarsiDate.GetDayOfMonth(Date).ToString());
return Result;
}
并查看
<%: Html.Encode(GenralClasses.FarsiDate.MiladiToShamsi(item.OrderDate) )%>
答案 0 :(得分:0)
试试这个
public static string MiladiToShamsi(DateTime Date)
{
string Result;
string Year;
string Month;
string Day;
# string Result, Year, Month, Day I don't know this works or not in asp.net
PersianCalendar FarsiDate = new PersianCalendar();
Year = FarsiDate.GetYear(Date).ToString();
Month = (FarsiDate.GetMonth(Date) < 10 ? "0" + FarsiDate.GetMonth(Date).ToString() : FarsiDate.GetMonth(Date).ToString());
Day = (FarsiDate.GetDayOfMonth(Date) < 10 ? "0" + FarsiDate.GetDayOfMonth(Date).ToString() : FarsiDate.GetDayOfMonth(Date).ToString());
Result = Year + "/" + Month + "/" + Day ;
return Result;
}
答案 1 :(得分:0)
获得此异常的唯一原因是 - item.OrderDate的类型不是DateTime。 Maby是的 字符串或其他东西。