我想在下拉菜单中显示时间。我设法使用这段代码: -
DateTime dtTime = new DateTime(2015,01,01,00,00,00);
DataTable dt = new DataTable();
dt.Columns.Add("time");
for (int i = 0; i < 48; i++)
{
string tm = dtTime.ToShortTimeString();
DataRow dr = dt.NewRow();
dr["time"] = tm;
dt.Rows.Add(dr);
dtTime = dtTime.AddMinutes(30);
}
ddlTime.DataSource = dt;
ddlTime.DataTextField = "time";
ddlTime.DataValueField = "time";
ddlTime.DataBind();
输出结果为: -
现在,我想制作hh:mm tt格式。例如,凌晨1:00应该是01:00 AM。谁能帮我?感谢。
答案 0 :(得分:1)
dtTime = dtTime.AddMinutes(30).ToString("HH:mm tt");
答案 1 :(得分:1)
替换
dtTime.ToShortTimeString();
与
dtTime.ToString("hh:mm tt");
答案 2 :(得分:1)
string tm = dtTime.ToString("hh:mm tt");