Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在HTML文本输入中显示C#DateTime_Javascript_C#_Html_Datetime - Fatal编程技术网

Javascript 在HTML文本输入中显示C#DateTime

Javascript 在HTML文本输入中显示C#DateTime,javascript,c#,html,datetime,Javascript,C#,Html,Datetime,因此,我从数据库中提取日期时间,并希望在HTML文本输入中显示它() 当C#DateTime被发送到Javascript时,它看起来是这样的:fooDate:{6/22/2011 2:30:00 PM}。但是,当它显示在中时,它最终看起来是这样的:2011-06-22T14:30:00 这有点烦人,因为我只关心显示日期。为什么会发生这种转换,有没有办法让它显示6/22/2011 2:30:00 PM位?不使用正则表达式可以实现这一点吗?尝试使用String.Format函数: //Here yo

因此,我从数据库中提取日期时间,并希望在HTML文本输入中显示它(

当C#DateTime被发送到Javascript时,它看起来是这样的:
fooDate:{6/22/2011 2:30:00 PM}
。但是,当它显示在
中时,它最终看起来是这样的:
2011-06-22T14:30:00


这有点烦人,因为我只关心显示日期。为什么会发生这种转换,有没有办法让它显示
6/22/2011 2:30:00 PM
位?不使用正则表达式可以实现这一点吗?

尝试使用String.Format函数:

//Here you pull the DateTime from your db
//I show you an example with the current DateTime
DateTime myDateTime = DateTime.Now; 

string date = String.Format("{0:dd-MM-yyyy}", myDateTime); //eg: 02-12-2014

//Place the string in your textbox
this.txtYourTextbox.Text = date;
如果您不知道使用哪种格式,请参阅以下文章:


尝试使用String.Format函数:

//Here you pull the DateTime from your db
//I show you an example with the current DateTime
DateTime myDateTime = DateTime.Now; 

string date = String.Format("{0:dd-MM-yyyy}", myDateTime); //eg: 02-12-2014

//Place the string in your textbox
this.txtYourTextbox.Text = date;
如果您不知道使用哪种格式,请参阅以下文章:


在将其传递给JS方法之前,是否能够将其转换为字符串

string Output = string.Format("{0:G}",DatabaseValue);

在将其传递给JS方法之前,是否能够将其转换为字符串

string Output = string.Format("{0:G}",DatabaseValue);

混合搭配你想要的任何组合。世界就是你的牡蛎

DateTime.Now.Day
DateTime.Now.Month
DateTime.Now.Year

混合搭配你想要的任何组合。世界就是你的牡蛎

DateTime.Now.Day
DateTime.Now.Month
DateTime.Now.Year

刚开始约会的例子

DateTime.Now.ToShortDateString();
将返回“2014年12月2日”

也可以指定所需的格式

DateTime.Now.ToString("yyyy-MM-dd");

将返回“2014-12-02”

仅获取日期的示例

DateTime.Now.ToShortDateString();
将返回“2014年12月2日”

也可以指定所需的格式

DateTime.Now.ToString("yyyy-MM-dd");

将返回“2014-12-02”

如何在输入中显示日期?如何在输入中显示日期?