c#从特定日期提取星期几

2024-12-03 05:07:36
推荐回答(2个)
回答1:

DateTime.Now.DayOfWeek;
new DateTime().DayOfWeek;
DayOfWeek是一个星期几的枚举

DateTime birth = new DateTime(1991, 2, 2);
DayOfWeek week = birth.DayOfWeek;

回答2:

using System;
using System.Collections.Generic;
using System.Text;

namespace Proj2_1
{
class Program
{
struct Stud
{
public int studn;
public string name;
public string bday;
}
static void Main(string[] args)
{
Stud s1, s2;
s1.studn = 101;
s1.name = "郭靖";
s1.bday ="1991,1,1";
DateTime dt=DateTime.Parse(s1.bday);
Console.WriteLine("学号:{0},姓名:{1},出生日期{2} {3}",s1.studn,s1.name,s1.bday,dt.DayOfWeek.ToString());
s2.studn = 102;
s2.name = "黄蓉";
s2.bday ="1991,2,2";
dt=DateTime.Parse(s1.bday);

Console.WriteLine("学号:{0},姓名:{1},出生日期{2} {3}",s2.studn,s2.name,s2.bday,dt.DayOfWeek.ToString());
}
}
}