C#獲取日期的星期名稱

_York發表於2018-08-15
 private string GetWeekName(DayOfWeek week)
        {
            string weekName = "";
            switch (week)
            {
                case DayOfWeek.Friday:
                    weekName = "週五";
                    break;
                case DayOfWeek.Monday:
                    weekName = "週一";
                    break;
                case DayOfWeek.Saturday:
                    weekName = "週六";
                    break;
                case DayOfWeek.Sunday:
                    weekName = "週日";
                    break;
                case DayOfWeek.Thursday:
                    weekName = "週四";
                    break;
                case DayOfWeek.Tuesday:
                    weekName = "週二";
                    break;
                case DayOfWeek.Wednesday:
                    weekName = "週三";
                    break;
                default:
                    break;
            }
            return weekName;
        }

使用方式:

  

GetWeekName(DateTime.Now.DayOfWeek),

 

相關文章