[已解决] datetime格式,在asp.net中为24小时格式 [英] [SOLVED] datetime format in asp.net in 24 hrs format
本文介绍了[已解决] datetime格式,在asp.net中为24小时格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我的页面上有一个标签,并且设置了这样的内容
Label1.Text = DateTime.Now.ToString("T");它以12小时格式显示以小时和分钟为单位的时间.
但我想要24小时制.
意思是下午2:14应该是14:14.请让我知道该怎么做?
谢谢你
mohd.wasif
编辑-被OP标记为已解决. -Ankur
Hi All,
I have a label in my page and have set like this
Label1.Text=DateTime.Now.ToString("T"); it''s is showing time in hours and minutes as per 12 hours format.
But I want in 24 hours format.
means 2:14 pm should be 14:14 .Please let me know how to do it?
Thanking you
mohd.wasif
Edit - Marked solved as commented by OP. - Ankur
推荐答案
尝试一下,
Try this,
DateTime.Now.ToString("HH:mm")
试试这个..
try this one..
static void Main()
{
DateTime dateTime = DateTime.Now;
C.WriteLine ("d = {0:d}", dateTime );
C.WriteLine ("D = {0:D}", dateTime );
C.WriteLine ("f = {0:f}", dateTime );
C.WriteLine ("F = {0:F}", dateTime );
C.WriteLine ("g = {0:g}", dateTime );
C.WriteLine ("G = {0:G}", dateTime );
C.WriteLine ("M = {0:M}", dateTime );
C.WriteLine ("R = {0:R}", dateTime );
C.WriteLine ("s = {0:s}", dateTime );
C.WriteLine ("t = {0:t}", dateTime );
C.WriteLine ("T = {0:T}", dateTime );
C.WriteLine ("u = {0:u}", dateTime );
C.WriteLine ("U = {0:U}", dateTime );
C.WriteLine ("Y = {0:Y}", dateTime );
C.WriteLine ("Month = " + dateTime.Month);
C.WriteLine ("Day Of Week = " + dateTime.DayOfWeek);
C.WriteLine ("Time Of Day = " + dateTime.TimeOfDay);
C.WriteLine("DateTime.Ticks = " + dateTime.Ticks);
}
这篇关于[已解决] datetime格式,在asp.net中为24小时格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文