实现如下目的: 
1、录入一个同学的出生日期,如:2009年3月6日 
2、输出那天是星期几,如:星期五

解决方案 »

  1.   

    获取输入的日期是一周中的第几天
    Convert.ToDateTime("2009-03-06").DayOfWeek;
    然后再排出是星期几
      

  2.   

    string str = "2009年3月6日";
            Match m = Regex.Match(str, @"(\d+)\D(\d+)\D(\d+)\D");
            if (m.Success)
            {
                string[] week={"日","一","二","三","四","五","六"};
                DateTime d = new DateTime(Convert.ToInt32(m.Groups[1].Value), Convert.ToInt32(m.Groups[2].Value), Convert.ToInt32(m.Groups[3].Value));
                Response.Write("当天是星期" + week[(int)d.DayOfWeek]);
            }
      

  3.   


            string dateStr="2009年3月9日";
            DateTime dt;
            DateTime.TryParse(dateStr, out dt);
            string[] week ={ "日", "一", "二", "三", "四", "五", "六" };
            Response.Write( dateStr + " 是星期" + week[(int)dt.DayOfWeek]);
      

  4.   

    顶下,Match m = Regex.Match(str, @"(\d+)\D(\d+)\D(\d+)\D");没用过
      

  5.   


            string dateStr="2009年3月9日";
            DateTime dt;
            if(DateTime.TryParse(dateStr, out dt))
            {
                string[] week ={ "日", "一", "二", "三", "四", "五", "六" };
                Response.Write( dateStr + " 是星期" + week[(int)dt.DayOfWeek]);
            }