C# 获取当前星期几三种实现方法
程序员文章站
2024-03-03 21:31:52
第一种: 复制代码 代码如下: string[] day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五"...
第一种:
string[] day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string week = day[convert.toint32(datetime.now.dayofweek.tostring("d"))].tostring();
lbday.text = week;
第二种:
lbday.text = system.globalization.cultureinfo.currentculture.datetimeformat.getdayname(datetime.now.dayofweek);
第三种:
public static string dt;
public static string week;
dt = datetime.today.dayofweek.tostring();
switch (dt)
{
case "monday":
week = "星期一";
break;
case "tuesday":
week = "星期二";
break;
case "wednesday":
week = "星期三";
break;
case "thursday":
week = "星期四";
break;
case "friday":
week = "星期五";
break;
case "saturday":
week = "星期六";
break;
case "sunday":
week = "星期日";
break;
}
lbday.text = week;
复制代码 代码如下:
string[] day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string week = day[convert.toint32(datetime.now.dayofweek.tostring("d"))].tostring();
lbday.text = week;
第二种:
复制代码 代码如下:
lbday.text = system.globalization.cultureinfo.currentculture.datetimeformat.getdayname(datetime.now.dayofweek);
第三种:
复制代码 代码如下:
public static string dt;
public static string week;
dt = datetime.today.dayofweek.tostring();
switch (dt)
{
case "monday":
week = "星期一";
break;
case "tuesday":
week = "星期二";
break;
case "wednesday":
week = "星期三";
break;
case "thursday":
week = "星期四";
break;
case "friday":
week = "星期五";
break;
case "saturday":
week = "星期六";
break;
case "sunday":
week = "星期日";
break;
}
lbday.text = week;