Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is a simple question but I just stuck here. I want to get the month and create the folder respectively.
Say
C#
DateTime.Now.Month.ToString()

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

1 solution

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:

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

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


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900