在数据库中保存日期时间时出现问题 [英] problem while saving date time in database
本文介绍了在数据库中保存日期时间时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
plz 请帮助我.在我的项目中,一个字段是"CreatedOn
",并保存该日期.对于数据库中的该字段,它具有datetime数据类型,并且在保存时我将其转换为字符串::
hdfCreatedOn.Value = Convert.ToString(DateTime.Today);
但是它将日期保存为2012-06-27 00:00:00.000
,但不显示时间.
解决方案
尝试使用-
hdfCreatedOn.Value = Convert.ToString(DateTime.Now);
有关详细信息,请通过此-
C#datetime-format [ ^ ]
尝试以下代码:
hdfCreatedOn.Value = Convert.ToString(DateTime.Now); hdfCreatedOn.Value = 字符串 .Format(" ,DateTime.Now); // "2012年6月27日下午4:32" hdfCreatedOn.Value = 字符串 .Format(" ,DateTime.Now); // 2012年6月27日4:32:07 PM
plz Please help me. In my project one field is ''CreatedOn
'' and in that saving date time. for that field in database it has datetime datatype and while saving it i am converting in into string as :
hdfCreatedOn.Value = Convert.ToString(DateTime.Today);
But it saves date as 2012-06-27 00:00:00.000
it not shows time.
解决方案
Try using -
hdfCreatedOn.Value = Convert.ToString(DateTime.Now);
For details go through this-
C# datetime-format[^]
Try below code:
hdfCreatedOn.Value = Convert.ToString(DateTime.Now); hdfCreatedOn.Value = String.Format("{0:g}", DateTime.Now); // "6/27/2012 4:32 PM" hdfCreatedOn.Value = String.Format("{0:G}", DateTime.Now); // "6/27/2012 4:32:07 PM"
这篇关于在数据库中保存日期时间时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文