asp.net dateTime格式问题... [英] Asp.net dateTime format issue......

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

问题描述

如何在SQL SERVER QUERY中将 2011年9月2日03:10 PM格式化为03:10 PM



请帮助

How to format 9/2/2011 03:10 PM to 03:10 PM in SQL SERVER QUERY




Please Help

推荐答案

嗨 Kishore,

请使用以下任何内容

Hi Kishore,

Please use any from following

SELECT GETDATE() --Full Date and Time
SELECT CONVERT(varchar, GETDATE(), 108) --24 Hours Time
Select LTRIM(RIGHT(CONVERT(char(19),GETDATE(),100),7)) --12 Hours Time




谢谢,
Imndadhuse




Thanks,
Imndadhuse


假定日期为DateTime,请尝试:
Assuming you have the date as a DateTime, try:
DateTime dt = new DateTime(2011, 2, 9, 15, 10, 0);
Console.WriteLine(dt.ToString("hh:mm tt"));

此处有DateTime所有格式选项的列表:

There is a list of all the formatting options for DateTime here: Formatting a DateTime for display - format string description[^]


假设您要在网页上显示格式化的数据,则可以如下使用DateTime类的成员.下面的示例演示如何从给定的DateTime对象中提取小时和分钟.

Assuming that you are going to show the formatted data on the web page you can use the members of the DateTime class as follows. The example below shows how to extract hours and minutes from a given DateTime object.

//Store the value from the database into a DateTime object like the one below
DateTime DateAndTime;

//Get the hour from the object
int hours = DateAndTime.Hour();

//Get the minutes from the object
int minutes = DateAndTime.Minute();



现在使用整数变量根据需要提供自定义输出.

我的代码块是可悲的. >.>



Use the integer variables now to give a custom output as required.

My code block is pathetic. >.>


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

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