0

I have a textbox and i would love it to be formatted. fortunately for me, i can get this done by changing the textmode = DateTimeLocal. Exactly what I want. Additionally, I would like to load this textbox with default values rather than leaving it with dd/mm/yy __:__:__ . I can change the text if it is a regular textbox (single mode) or even a datetime textbox. but i cannot change it with DateTimeLocal mode. some help please. thank you.

4

3 回答 3

6

您必须将 DateTime 格式化为可以解析的有效日期和时间字符串,这是一个有效的字符串:

txtDateTimeLocal.Text = DateTime.Now.ToLocalTime().ToString("yyyy-MM-ddTHH:mm");

有关您可以设置的其他属性的更多详细信息,请参阅: http: //www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#local-date -and-time-state-(type=datetime-local)

于 2013-10-03T16:18:12.797 回答
1

尝试设置整个日期时间格式,包括秒和毫秒,对我有用。

txtStartTime.Text = DateTime.Today.ToString("yyyy-MM-ddTHH:mm:ss.ss");
于 2018-11-28T17:47:34.377 回答
0

如果要从数据库动态设置 TextBox 的 DateTime,则可以使用以下代码:

DataTable dtTemp = (DataTable)ViewState["DataSet"]; //  this are temporary table

TextBox txtFromDate = (TextBox)gridEditBloackHomework.Rows[e.NewEditIndex].FindControl("txtFromDate");
TextBox txtToDate = (TextBox)gridEditBloackHomework.Rows[e.NewEditIndex].FindControl("txtToDate");
string c = dtTemp.Rows[e.NewEditIndex]["FromDate"].ToString();
DateTime FromDate = Convert.ToDateTime(dtTemp.Rows[e.NewEditIndex]["FromDate"]);
DateTime ToDate = Convert.ToDateTime(dtTemp.Rows[e.NewEditIndex]["ToDate"]);
DateTime dtFromDate = FromDate.AddHours(-2);
DateTime dtToDate = ToDate.AddHours(-2);
txtFromDate.Text = dtFromDate.ToLocalTime().ToString("yyyy-MM-ddTHH:mm").ToString();
txtToDate.Text = dtToDate.ToLocalTime().ToString("yyyy-MM-ddTHH:mm");
于 2017-06-01T13:51:34.207 回答