全英文版时间格式化07/29/2010 4:14:01 PM
之前格式化,AM PM出不来,总是显示上午 下午
aspx页面的绑定:
<%#Eval("AddDate") == DBNull.Value ? "" : Convert.ToDateTime(Eval("AddDate")).ToString("MM/dd/yyyy h:mm:ss tt", new System.Globalization.CultureInfo("en-US", false).DateTimeFormat)%>
类代码编写:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Globalization.DateTimeFormatInfo myDTFI = new System.Globalization.CultureInfo("en-US", false).DateTimeFormat;//如果是中国用zh-cn
DateTime dt = DateTime.Now;
string a=dt.ToString("MM/dd/yyyy H:mm:ss tt", myDTFI);
Response.Write(a);
}
}
两者取其一均可实现: