如何确定太阳日为两个日期。 如果日复一日,从两天的差额中减去一天
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
如何确定太阳日为两个日期。 如果日复一日,从两天的差额中减去一天
如果我理解正确的话,你正在寻找这样的东西:
public static bool DoesIncludeSunday(DateTime startDate, DateTime endDate)
{
bool r = false;
TimeSpan testSpan = new TimeSpan(6, 0, 0, 0);
TimeSpan actualSpan =endDate - startDate;
if (actualSpan >= testSpan) { r = true; }
else
{
DateTime checkDate = endDate;
while (checkDate > startDate)
{
r = (checkDate.DayOfWeek == DayOfWeek.Sunday);
if(r) { break; }
checkDate = checkDate.AddDays(-1);
}
}
return r;
}
最终结果必须是最近的日期。 第一部分简单地使我们无法检查开端和终点日期是否相隔了6天以上(这将包括一个日,因此无需继续)。 第二步只是从结束语检查(如果星期日在那里)开始一天后走。
一旦你知道太阳日是否是时段的一部分,你就可以对你从呼吁守则中想要的日期作任何改动。
仅仅因为我要cl,我就这样写了:
public static int DaysExcludingSundays(DateTime start, DateTime end)
{
return ((end - start).Days + 1) - ((((end - start).Days + 1) + (((int)start.DayOfWeek + 6) % 7)) / 7);
}
感到可以在不理解该守则的含义的情况下复制和复制该守则。 我感到迷惑。
缩略语:
int startOffset = ((int) start.DayOfWeek + 6) % 7;
int totalInclusiveDays = (end - start).Days + 1;
int numberOfSundays = (totalInclusiveDays + startOffset) / 7;
int numberOfDaysWithoutSundays = totalInclusiveDays - numberOfSundays;
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!