从周数计算月份
我从数据库中获取周号,需要计算它是该月的哪一周。
例如:
week no = 7 month = 2
week no 11 month = 3
如何计算?
只是补充一下,我还有年份值和周号。
i am getting week no from database need to calculate which week of the month it is.
for ex:
week no = 7 month = 2
week no 11 month = 3
How to calculate it??
Just to add on i also have the year value with the week no.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好吧,我会尝试一下,但它不是很漂亮:
这考虑到了生成周的文化特定规则。如果一周分为两个月,它将返回它遇到的第一个月。
因此,在挪威,我会使用
CalendarWeekRule.FirstFourDayWeek
和DayOfWeek.Monday
来调用它以获得正确的结果。Ok, I'll have a go, but it's not very pretty:
This takes into consideration the culture specific rules for generating weeks. If a week is split between two months it will return the first month it encounters.
So in Norway, I would call this with
CalendarWeekRule.FirstFourDayWeek
andDayOfWeek.Monday
for correct results.根据周数计算日期:
根据周数计算日期
获取月份的周数:
计算 .NET 中的星期
Calculate a date from weeknumber:
Calculate date from week number
Get the WeekOfMonth:
Calculate week of month in .NET
假设您正在查找给定年份中的月份:
Assuming that you are looking for the month in the given year:
使用 DateTime,您可以将周数乘以 7,获取一年中过去的总天数,将这些天数添加到 31/12/yyyy-1,然后从结果 DateTime 中获取月份。
我希望这对你有用。
再见。
Using DateTime, you can multiply week number by 7, get the total days passed on the year, add those days to 31/12/yyyy-1 and the get the month from the resulting DateTime.
I hope this to be useful to you.
See you.
4 周 = 1 个月
所以使用
week%4
它会返回你的月份号
4 week = 1 month
so use
week%4
its return you no of month
这是使用 .NET 时间段库 的解决方案:
Here a solution using the Time Period Library for .NET: