获取特定格式的日期 [英] to get a date in particular format
本文介绍了获取特定格式的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个特定的孔中约会. MMM YYYY,代表当前日期,我应该获得2011年4月的收益.
请告诉我要使用哪个函数.
I want my date in a particular foramt ie. MMM YYYY, meaning for present date I should get APR 2011.
Please tell me which function to use.
推荐答案
尝试此链接
ClickHere [
try this link
ClickHere[^]
我建议您最后这样做应用程序,因为它是演示功能,而不是后端功能,并且使用起来稍微简单一些.
但是,对于SQL:
I would suggest that you did this in the end App, as it is a presentation feature rather than a back end, and it it slightly simpler to use.
However, for SQL:
SELECT DATENAME(MONTH, date) + ' ' + DATENAME(YEAR, YEAR(date)) AS Date FROM myTable
在.NET中,一旦您将日期读出到DateTime中,它将变得更加轻松和整洁:
In .NET it is easier and cleaner once you have read out the date into a DateTime:
string myDateString = myDate.ToString("MMM yyyy");
此处有.NET DateTime.ToString格式的代码列表: ^ ]
There is a list of .NET DateTime.ToString formattoing codes here: Formatting a DateTime for display - format string description[^]
这篇关于获取特定格式的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文