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

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Globalization;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Demo
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             string FriStr = GetDateOfDayInWeek(DateTime.Now, DayOfWeek.Friday);
15             Console.WriteLine(FriStr);
16             Console.ReadKey();
17         }
18 
19         static string GetDateOfDayInWeek(DateTime dt, DayOfWeek dw)
20         {
21             DateTime date = dt.AddDays(dw - dt.DayOfWeek);
22             //具体显示格式参见:https://msdn.microsoft.com/zh-cn/library/8tfzyc64.aspx
23             return date.ToString("dd MMMM yyyy", DateTimeFormatInfo.InvariantInfo);
24         }
25     }
26 }

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

posted @ 2017-01-12 15:12  天琊蓝  阅读(1009)  评论(1编辑  收藏  举报