DateTime对象问题 [英] DateTime objects problem

查看:70
本文介绍了DateTime对象问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在用asp .net(c#)开发一个项目,但日期时间对象有问题.
我在ms-sql中有很多带有日期的记录,我正在尝试以24小时格式(不是AM或PM)在网页中显示日期.但是我不能那样做.
我将服务器的区域选项更改为24小时格式,但没有用.

有没有办法在代码(c#)端更改此格式?

谢谢,

Hi everyone,

I have developing a project with asp .net (c#) and i have problem with the date-time objects.
I have many records in ms-sql with dates, i am trying show that dates in a web page in this 24-hour format (not AM or PM). But i cannot do that.
I was change server''s regional options to 24-hour format but it did not work.

Is there a way to change this format in a code(c#) side ?

Thanks,

推荐答案

使用 DateTime.ToString [^ ]
例如yourDate.ToString("dd/MM/yyyy HH:mm:ss")(HH为24小时| hh为12小时)
Use DateTime.ToString[^]
like, yourDate.ToString("dd/MM/yyyy HH:mm:ss") (HH for 24 hours | hh for 12 hours)


不要触摸您的服务器选项:如果您希望以客户端"首选格式显示日期/时间尽可能.
MSDN可以为您提供帮助: http://msdn.microsoft.com/en-us/library/bb882561.aspx [ ^ ]

或者,您也可以按照之前的建议使用DateTime.ToString-这里提供所有可用格式代码的列表:
Don''t touch your servers options: you want to display the date/time in the Clients preferred format if at all possible.
MSDN can help there: http://msdn.microsoft.com/en-us/library/bb882561.aspx[^]

Or you can use DateTime.ToString as previously suggested - there is a list of all the available format codes here: Formatting a DateTime for display - format string description[^]


当然,这是示例.
Ofcourse, here is example.
DateTime dt = System.DateTime.Now;
string strDate = dt.ToString("Date_Format_of_your_choice");


这篇关于DateTime对象问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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