2008/07/28

C#中文星期几的输出方法

在上一贴中(http://dotnetfans.blogspot.com/2008/07/c_28.html),其他输出都是中文的,但星期几的输出是英文的,下面写个输出中文星期几的代码:

public partial class WeekDay : System.Web.UI.Page

{

public static string TodayOfWeek(DateTime dt)

{

string[] WeekDayCn = new string[] { "日", "一", "二", "三", "四", "五", "六" };

return "今天是星期" + WeekDayCn[(int)dt.DayOfWeek];

}


protected void Page_Load(object sender, EventArgs e)

{

DateTime Dt = DateTime.Now;

Response.Write(TodayOfWeek(Dt));

}

}

输出:

今天是星期一

没有评论: