如何让每一天在下个月的名字吗? [英] How to get the name of each day in next month?

查看:131
本文介绍了如何让每一天在下个月的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTime dt = new DateTime();
dt = DateTime.Now.AddMonths(1);
int x = DateTime.DaysInMonth(dt.Year, dt.Month);
MessageBox.Show(x.ToString());  // works ok - 31

和我怎么能说以下内容:

And how can I say the following:

foreach (day in dt.Days)
{
string abc = dt.DayOfWeek.ToString();
MessageBox.Show(abc)
}



问题是在第一行 - 的foreach ...

Problem is in the first line - foreach...

推荐答案

这应该做的工作。

DateTime Base = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1);
int x = DateTime.DaysInMonth(Base.Year, Base.Month);
while (Base.Day != x)
{
    Console.WriteLine(Base.DayOfWeek.ToString());
    Base = Base.AddDays(1);
}

这篇关于如何让每一天在下个月的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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