记录一下项目中遇到的一些小问题
string GetTime()
{
hour = DateTime.Now.Hour;
minute = DateTime.Now.Minute;
second = DateTime.Now.Second;
month = DateTime.Now.Month;
year = DateTime.Now.Year;
day = DateTime.Now.Day;
string s = string.Format("{0:D2}:{1:D2}:{2:D2}"+" "+"{3:D4}/{4:D2}/{5:D2} ",hour,minute,second,year,month,day);
switch (DateTime.Now.DayOfWeek)
{
case DayOfWeek.Sunday:s += "星期天";
break;
case DayOfWeek.Monday:s += "星期一";
break;
case DayOfWeek.Tuesday:s += "星期二";
break;
case DayOfWeek.Wednesday:s += "星期三";
break;
case DayOfWeek.Thursday:s += "星期四";
break;
case DayOfWeek.Friday:s += "星期五";
break;
case DayOfWeek.Saturday:s += "星期六";
break;
}
return s+" 第 "+ WeekOfYear(DateTime.Now, new CultureInfo("zh-CN")).ToString()+" 周";
}
//获取某一天是这一年的第几周
public int WeekOfYear(DateTime dt, CultureInfo ci)
{
return ci.Calendar.GetWeekOfYear(dt, ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek);
}