一个月和一年的日期时间格式

编程入门 行业动态 更新时间:2024-10-25 04:22:19
本文介绍了一个月和一年的日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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.

更多推荐

一个月和一年的日期时间格式

本文发布于:2023-06-10 02:01:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/606250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:一个月   日期   格式   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!