使用正确的月份格式。 [英] Use the correct month format.

查看:105
本文介绍了使用正确的月份格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,但我只是坚持到这里。我想得到月份并分别创建文件夹。

It is a simple question but I just stuck here. I want to get the month and create the folder respectively.
Say

DateTime.Now.Month.ToString()



它是6,我可能需要06。


It is "6", I may need "06".

推荐答案

请阅读msTime页面上的DateTime tostring格式化



https://msdn.microsoft.com /en-us/library/8kb3ddd4(v=vs.110).aspx [ ^ ]



更新

实际上,考虑一下你可以使用ToString格式,或者string.Format。



这里有几个例子:



please read the msdn page on DateTime tostring formatting

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]

UPDATE
Oh actually, thinking about it you can use the ToString formatting, or the string.Format.

Here are a couple of examples:

string filename = "month " + DateTime.Now.ToString("MM"); 

int month = DateTime.Now.Month;
string = string.Format("month {0:D2}",month);  





要么可能是最好的 - 我会选择string.Format。我觉得它看起来更整洁



Either might be best - I would go for string.Format. I think it looks neater


这篇关于使用正确的月份格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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