您的位置:首页 > 编程语言 > C#

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

2017-01-12 15:12 316 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: