使用标签显示日期和时间 [英] display date and time using label

查看:100
本文介绍了使用标签显示日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我

我有时间在数据库表中作为

2012/10/15下午02:07:42

我已经使用标签Retreieved来显示数据库中的内容.

我需要使用标签显示为15/10/2012 02:07:42 pm. DD/MM/YYYY和时间.

请帮助我,我正在努力.

Please help me

I have time in database table as

10/15/2012 02:07:42 PM

I have Retreieved using label is displaying what ever it is in database.

I need to display as 15/10/2012 02:07:42 pm using label. DD/MM/YYYY and time.

Please help me, am trying a lot .

Thanks for ever.

推荐答案

一旦检索到它,请使用以下代码

Once you retrieve it use following code

string yourDate = "10/15/2012 02:07:42 PM";
DateTime datetime = DateTime.ParseExact(yourDate, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

string formattedDate = datetime.ToString("dd/MM/yyyy hh:mm:ss tt");



不要忘记使用System.Globalization命名空间进行添加!

希望能有所帮助.如果是这样,请将其标记为答案/赞.
谢谢
Milind



Dont forget to add using System.Globalization namespace!

Hope that helps. If it does, mark it as answer/upvote.
Thanks
Milind


如果在数据库中,日期列的数据类型为 DateTime ,则

将以下行用于C#中的输出,
if in database your date column''s datatype is DateTime then,

use below line for output in C#,
label1.Text = dt.Rows[0]["YourDateFieldNameFromDB"].Value.ToString("dd/MM/yyyy hh:mm tt");


祝您编码愉快!
:)

[Aman.A]更正了格式字符串错字[/Aman.A]


Happy Coding!
:)

[Aman.A]corrected the format string typo[/Aman.A]


在下面的代码中使用

Use below Code

label1.Text = DateTime.Value.ToString("dd/MM/yyyy hh:MM tt");


请参阅下面的链接
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]


Refer below link
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


这篇关于使用标签显示日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆