格式化时间为什么出错呢?public ...

来源:百度知道 编辑:UC知道 时间:2024/07/04 18:29:34
public string Gettime( DateTime time)
{

return Convert.ToDateTime(time).ToShortDateString();
// return DateTime.Now.ToShortDateString().ToString();

}

调用是 <asp:Label ID="JoinTime" runat="server" Text='<%# Gettime(Eval("JoinTime")) %>'></asp:Label>
怎么会出现

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: CS1502: 与“Soldier_SoldierList.Gettime(System.DateTime)”最匹配的重载方法具有一些无效参数

你检查下Eval("JoinTime")这个是不是日期时间型,
另外我建议你把Gettime( DateTime time)换成字符串string型,然后强制转换为日期,这样就肯定没问题了.

Eval("JoinTime"),检查一下 "JoinTime" 这个字段是否是时间类型

代码没有问题
你看看你的'<%# Gettime(Eval("JoinTime")) %>传出来的是不是正确的

<asp:Label ID="JoinTime" runat="server" Text='<%# Gettime(Eval("JoinTime")。ToString()) %>'></asp:Label>

public string Gettime( string time )
{

return Convert.ToDateTime((Datetime)time).ToShortDateString();
// return DateTime.Now.ToShortDateString().ToString();

}

ToString(“yyyy-MM-dd HH:mm:ss”);
格式 自己设置 这样能达到你要的效果不?
小时 hh 是12小时制 HH 是 24小时制
MM 是月 mm 是分