30秒学会 C# 片段 · 2019年10月3日

30秒学会 C# 片段 – DayOfTheWeek

Returns the string representation of the weekday for the given DateTime.

Use DateTime.ToString() with an appropriate format modifier to return the day of the week.

代码实现

public static partial class _30s 
{
  public static string DayOfTheWeek(DateTime date) 
  {
    return date.ToString("dddd");  
  }
}

使用样例

_30s.DayOfTheWeek(new DateTime(2020, 1, 15)); // "Wednesday"