在文本框中随意输入一个日期,单机“确定”按钮时显示这一天是星期几
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
enum Weekday {星期天,星期一,星期二,星期三,星期四,星期五,星期六};
private void button1_Click(object sender, EventArgs e)
{
DateTime dt = Convert.ToDateTime(textBox1.Text);
Weekday wd = (Weekday)dt.DayOfWeek;
label2.Text="这一天是" + wd + "。";
}
}
}