如何在asp.net 2.0中计算一年中的星期日数 [英] How to calculate number of sundays in a year in asp.net 2.0

查看:97
本文介绍了如何在asp.net 2.0中计算一年中的星期日数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net 2.0中计算一年中的星期日数?请帮助我 thnx 预先感谢

How to calculate number of sundays in a year in asp.net 2.0? Please help me thnx thanks in advance

推荐答案

在这里看看:http://stackoverflow.com/questions/248273/count-number-of-mondays-in-a-givend-date-范围 [ ^ ]


上面的解决方案太复杂了.
该号码通常是52.
如果一年的第一天是星期日,则为53.
如果是a年,并且一年的第一天是星期六,则为53.
因此:
The solutions above are far too complicated.
The number is generally 52.
If the first day of the year is a Sunday, it''s 53.
if it is a leap year, and the first day of the year is a Saturday, it is 53.
Hence:
int year = ...;
int retVal = 52;
DateTime firstDayOfYear = new DateTime(year, 1, 1);
if (firstDayOfYear.DayOfWeek == DayOfWeek.Sunday)
{
    retVal = 53;
}
if ((firstDayOfYear.DayOfWeek == DayOfWeek.Saturday)
    && (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)))
{
    retVal = 53;
}


尝试google :)让我为您做到这一点

http://lmgtfy.com/?q=calculate+number+of+sunday+使用+ c%23
Try google :) let me do that for you

http://lmgtfy.com/?q=calculate+number+of+sunday+using+c%23


这篇关于如何在asp.net 2.0中计算一年中的星期日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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