返回当月的星期数. [英] Return Week Number of the Current month.

查看:102
本文介绍了返回当月的星期数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队,
必需的功能是获取给定日期的返回星期数.
假设8th March 2010是给定的日期,则它应该在第二周返回"2" .我实现了下面的方法,该方法返回一年中的第几周,而要求是当前月份的第几周.
任何人都可以帮助我摆脱这种情况.

Hi Team,
Required functionality is to get the return week number of a given date.
Supposed 8th March 2010 is the given date then it should return "2" as 2nd week. I have implemented a below method which return week number of the year, whereas requirement is return week no of the current month.
Could any body help me out from this scenario.

public static int GetWeekNumber(DateTime dtPassed)
{
    CultureInfo ciCurr = CultureInfo.CurrentCulture;
    int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
    return weekNum;
}


塔伦·辛格(Tarun Singh). :laugh:
在此先感谢.

[更正了损坏的格式]


Tarun Singh. :laugh:
Thanks in Advance.

[Corrected broken formatting]

推荐答案

1.检查一周中的一天中给定日期的第一天
2.仅取给定日期的天"值
3.基于1和2点以及因子7(一周中的天数),您可以得到它.
对吧?


虽然更简单的方法是:
1.检查给定日期的月份的第一天的WeekOfYear = x
2.检查给定日期= y
的WeekOfYear 3.当前月份的周数= y-x + 1

希望能解决所有问题!
1. Check the day of the week for the 1st of given dates month
2. Take just the "day" value of given date
3. Based on point 1 & 2 and the factor 7 (days in a week), you can get it.
Right?


Though simpler approach would be:
1. Check the WeekOfYear of 1st of given date''s month = x
2. Check the WeekOfYear of the given date = y
3. Week Number of current month = y-x+1

Hope that solves it all!


这篇关于返回当月的星期数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆