C#中的格式化日期 [英] formatting date in C#
本文介绍了C#中的格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从MS-Access数据库中检索日期.在数据库中,"TDate"为dd-MM-yy格式.但是,当我为网格检索它时,它并没有以正确的格式显示.我也尝试将其转换为日期时间,但没有发生.有人可以帮我吗?
I am retrieving date from MS-Access database. In the database ''TDate'' is in dd-MM-yy format. But when I am retrieving it for a grid, it is not showing in the correct format. I also tried to convert it into datetime, but it doesn''t happen. Can somebody help me out?
IFormatProvider culture = new CultureInfo("hi-IN", true);
TDate =ds.Tables["tbl_Bank_Book"].Rows[i]["TDate"].ToString();
// dt = Convert.ToDateTime(TDate,culture);
// DateTime t = DateTime.Parse(TDate, culture);
// dt = DateTime.ParseExact(TDate, "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault);
推荐答案
请参考这篇文章
http://www.codedigest.com/Articles/ASPNET/137_How_to_format_DateTime_in_GridView_BoundColumn_and_TemplateColumn.aspx ^ ]
Hi,
Please refer this article
http://www.codedigest.com/Articles/ASPNET/137_How_to_format_DateTime_in_GridView_BoundColumn_and_TemplateColumn.aspx[^]
不说这是WinForms还是ASP/WebForm应用程序,仅提及网格"只会使事情更加混乱,因为存在多种网格".
如果它是WinForms,而您实际上的意思是DataGridView,则 ^ ]使用CellFormatting事件修改数据进行显示的示例可能会很有用.甚至提供了日期示例.
You do not say if this is a WinForms or ASP/WebForm application and simply referring to a ''grid'' only confuses things more as there are several varieties of ''grid''.
If it is WinForms and you do actually mean a DataGridView, then this[^] example of using the CellFormatting event to modify data for display might be useful. It even gives an example for Dates.
签出DateTime.ParseExact
方法:
http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx [ ^ ]
编辑============
我不知道为什么这被否决了.ParseExact
将解决他的问题.
Checkout theDateTime.ParseExact
method:
http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx[^]
EDIT============
I don''t know why this was down-voted.ParseExact
will address his problem.
这篇关于C#中的格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文