如何使用 C# 将月或日转换为 2 位数字字符串
例如:(02 而不是 2)
最佳答案
如果你有一个DateTime
,使用its string formatters :
string month = DateTime.Now.ToString("MM"); // or "dd" for day
或者,如果使用您已有的数字更有意义,请使用 the numeric formatters :
string monthStr = monthInt.ToString("00");
关于c# - 如何使用 C# 将月或日转换为 2 位数字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19233486/