C#获取本周五日期字符串

时间:2023-03-09 06:14:31
C#获取本周五日期字符串
 using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Demo
{
class Program
{
static void Main(string[] args)
{
string FriStr = GetDateOfDayInWeek(DateTime.Now, DayOfWeek.Friday);
Console.WriteLine(FriStr);
Console.ReadKey();
} static string GetDateOfDayInWeek(DateTime dt, DayOfWeek dw)
{
DateTime date = dt.AddDays(dw - dt.DayOfWeek);
//具体显示格式参见:https://msdn.microsoft.com/zh-cn/library/8tfzyc64.aspx
return date.ToString("dd MMMM yyyy", DateTimeFormatInfo.InvariantInfo);
}
}
}

更多日期显示格式参照:http://www.cnblogs.com/ATree/archive/2010/06/06/CSharp-DateTime-Tostring-LongDatePattern.html