Code
using System;
namespace TestDemo01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
int mIntStart_time = Convert.ToInt32("00");
int mIntEnd_time = Convert.ToInt32("23");
DateTime startTime = Convert.ToDateTime("2022/06/01");
DateTime endTime = Convert.ToDateTime("2022/06/01");
for (DateTime time = startTime; time <= endTime; time = time.AddDays(1))
{
for (int i = mIntStart_time; i <= mIntEnd_time; i++)
{
// 方法一
Console.WriteLine(i.ToString("D2"));
// 方法二 在给定字符串的左侧补充指定字符('0')到我们指定的长度(2)
//Console.WriteLine(Convert.ToString(i).PadLeft(2, '0'));
}
}
Console.ReadKey();
}
}
}
效果
Other
参考
C# 日记-PadLeft、PadRight用法:https://blog.csdn.net/Dragon_Raja/article/details/120050269
C# 字符串格式化_C# 字符串格式化整理:https://blog.csdn.net/u011127019/article/details/110286501