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]); }
Convert.ToDateTime("2009-03-06").DayOfWeek;
然后再排出是星期几
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]);
}
string dateStr="2009年3月9日";
DateTime dt;
DateTime.TryParse(dateStr, out dt);
string[] week ={ "日", "一", "二", "三", "四", "五", "六" };
Response.Write( dateStr + " 是星期" + week[(int)dt.DayOfWeek]);
string dateStr="2009年3月9日";
DateTime dt;
if(DateTime.TryParse(dateStr, out dt))
{
string[] week ={ "日", "一", "二", "三", "四", "五", "六" };
Response.Write( dateStr + " 是星期" + week[(int)dt.DayOfWeek]);
}