一个月和一年的日期时间格式 [英] Datetime format for a month and year
本文介绍了一个月和一年的日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DateTime ExpMonth = Convert.ToInt32(ddExpMonth); ---- DropDown(user selects a month)
DateTime ExpYear = Convert.ToInt32(ddExpYear); ---- Dropdown(user selects year)
Datetime ExpDate = ///// I want this part to be saved as Datetime 02/2012
这怎么可能.或其他任何方式.
How is this possible. Or any other way.
推荐答案
DateTime
值不知道格式-它只是一个日期和时间.您可以使用相关信息创建新的 DateTime
值:
A DateTime
value doesn't know about a format - it's just a date and a time. You can create a new DateTime
value with the relevant information:
DateTime expiry = new DateTime(Convert.ToInt32(ddExpYear),
Convert.ToInt32(ddExpMonth),
1);
...但是如何保存"完全取决于您.如果您提供更多信息,我们可能会为您提供更多帮助.您可以轻松地将其格式化为字符串:
... but how that is "saved" is entirely up to you. If you give us more information, we may be able to help you more. You can format it to a string easily enough:
string formatted = expiry.ToString("yyyy/MM");
...但是那可能不是你想要的.
... but that may not be what you're after.
这篇关于一个月和一年的日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文