c#用vs如何得到上个月的今天是周几。
大佬们救命。
直接调用现有函数
DateTime nyt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
nyt = nyt.AddMonths(-1);
var xq = nyt.DayOfWeek;
MessageBox.Show (nyt.DayOfWeek.ToString());
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_8
{
class Program
{
static void Main(string[] args)
{
//定义时间
int year = 2015, month = 2, day = 13;
//用户输入
//年
Console.Write("Please input year = ");
year = Convert.ToInt32(Console.ReadLine());
Console.Write("\n");
//月
Console.Write("Please input month = ");
month = Convert.ToInt32(Console.ReadLine());
Console.Write("\n");
//日
Console.Write("Please input day = ");
day = Convert.ToInt32(Console.ReadLine());
Console.Write("\n");
if(month == 1 || month == 2)
{
year = year - 1;
month = month + 12;
}
int week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400 + 1) % 7;
Console.WriteLine("the week is {0}", week);
}
}
}