Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#时间步进循环 #89

Open
landv opened this issue Aug 14, 2024 · 0 comments
Open

C#时间步进循环 #89

landv opened this issue Aug 14, 2024 · 0 comments

Comments

@landv
Copy link
Owner

landv commented Aug 14, 2024

class Program
{
    static void Main()
    {
        DateTime start = new DateTime(2024, 1, 1, 0, 0, 0); // 起始时间
        DateTime end = new DateTime(2024, 1, 20, 22, 0, 0); // 结束时间
        TimeSpan interval = TimeSpan.FromHours(2); // 步进值

        for (DateTime current = start; current <= end; current = current.Add(interval))
        {
			//            Console.WriteLine(current); // 打印当前时间
			int year = current.Year;
			int month = current.Month;
			int day = current.Day;
			int hour = current.Hour;

			//Console.WriteLine($"年: {year}, 月: {month}, 日: {day}, 时: {hour}");
			// 输出时间点和 "男"
			Console.WriteLine($"年: {year}, 月: {month}, 日: {day}, 时: {hour}, 性别: 男");

			// 输出时间点和 "女"
			Console.WriteLine($"年: {year}, 月: {month}, 日: {day}, 时: {hour}, 性别: 女");
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant