How to set the value of a textbox textmode=date AS

2019-01-09 12:00发布

Please help me if you can.

I'm trying to set a textbox textmode=date from a variable.

It's like this:

txtDataDespesa.Text = d.DataDespesa.ToShortDateString();

The problem is, when I go to visualize the page, the value of d.DataDespesa.ToShortDateString() isn't showing in the txtDataDespesa, instead is the default values dd/mm/yyyy

Thanks in advance.

3条回答
The star\"
2楼-- · 2019-01-09 12:44

afaik, the new textbox in .Net with textmode=date only supports the YYYY-MM-DD format.

txtDataDespesa.Text = d.DataDespesa.ToString("yyyy-MM-dd")

if you need the short date string, you need to use a regular textbox.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-09 12:44
dt_calculate_to_date.Text = DateTime.Today.ToString("yyyy-MM-dd");

will work and worked

if !ispostback
查看更多
乱世女痞
4楼-- · 2019-01-09 12:58

This has nothing to do with asp.net, but Html5. When using type="date" you should always use the format yyyy-MM-dd (W3C standard)

The problem is that in browsers that don't support type=date, this will show up as 2014-03-30, but on browsers that do support it, it is displayed according to the regional settings in the client OS.

So it may be 2014-03-30, 30.March.2014 or Mar-30-2014, you have no control over the format, the user has.

查看更多
登录 后发表回答