[英]How do I get the first day in a week Week, Year (gregorian calendar) in C#?
I need to calculate the date of the first day in a calendar week given a year/week, eg 我需要计算给定的年/周的日历周的第一天的日期,例如
Week 53 in 2009 -> Mon, 28.12.2009 2009年第53周-> 2009年12月28日星期一
Week 1 in 2010 -> Mon, 04.01.2010 2010年第1周-> 2010年1月4日,星期一
How would you wirte that code? 您将如何编写该代码?
PS: In the Gregorian calendar the first week of a year is the first week with 4 days. PS:在公历中,一年的第一周是带有4天的第一周。
If you don't want to do all the calculation yourself, use the System.Globalization.Calendar
class. 如果您不想自己进行所有计算,请使用
System.Globalization.Calendar
类。 I think you can use the GetDayOfYear()
method to get what you need. 我认为您可以使用
GetDayOfYear()
方法获取所需的内容。
Check this MSDN library for the example. 检查此MSDN库以获取示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.