如何在ASP.Net c#中找到42天为1个月1周5天 [英] How to find 42 days as 1 month 1 week 5 days in ASP.Net c#

查看:65
本文介绍了如何在ASP.Net c#中找到42天为1个月1周5天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将两个日期之间的差异定为42天,我想要一个程序用于应用惩罚值,首先是月份(它是3),每周(它是2),白天(它是1) 。什么是C#代码?

Hi, I have the difference between two dates as 42 days, I want a program for apply penalty value on it, first as monthwise(it is 3), weekwise(it is 2), daywise(it is 1) respectively. What is C# code for this?

推荐答案

这并不是那么简单:日期之间的差异是一个时间跨度 - 这与任何特定日期无关。年,所以不能表示为月,周和天计数 - 如果开始日期是2月27日,那么你得到的数字会有很大差异,例如3月27日。

您想要的是相对于特定日期的时间跨度 - 年龄:与年龄一起工作:它与TimeSpan不同! [ ^ ]
It's not that simple: the "difference" between to dates is a timespan - which is not related to any particular day of the year, and so can't be expressed as a "months", "weeks" and "days" count - the numbers you would get would vary considerably if the start date was February 27th to those you would get for March 27th for example.
What you want is a timespan that is relative to a particular date - an Age: Working with Age: it's not the same as a TimeSpan![^]


我不认为这是可能的或逻辑的。你不能在代码中使用datetime,或者你不能说我需要2月31日的报告。你必须定义自己。你可以在能够做到这一点。

说你有一个包含这个字段monthName,dates等的表。
I don't think it is possible or logical.you can't use datetime in the code or you can't say i need a report of February 31st.you have to define yourself.you can create a table to do this.
say you have a table with this fields monthName, dates etc.


我会从所有月份的数组开始用数字他们在他们身上的日子。这将允许您解决上面所述的问题。



我将开始解决的最大问题。是一个月28,29,30或31天还是一个月意味着下个月完全相同的日期<暧昧我知道,但让我告诉你。在正常月份,我们可以说Jan.可能有31天。从1月2日起的一个月将是2月2日。上面的数组可以解决这个问题。你将遇到的最大问题是今天是第29个问题。从今天起1个月是什么? 2月29日也是2月28日或3月1日。



使用上面的数组并解决从现在开始的一个月不存在的问题或者说从现在开始一个月是等于当月的天数,因此从1月31日起的一个月将是3月3日(自1月31日起31天)。无论如何,有几种方法可以解决这个问题。之后解决了它非常琐碎的代数。
I would start with an array of all the months with the number of days they have in them. This would allow you to work around what has been stated above.

The biggest questions I would start with to work around. Is one month 28, 29, 30, or 31 days or does one month mean exactly the same date next month < ambiguous I know but let me show you. In a normal month lets say Jan. there might be 31 days. A month from the 2nd of January would be the 2nd of February. The above array would work through that. The biggest problem you are going to run into is that today is the 29th. 1 month from today is what? the 29th of February so does it become the 28th of February or the 1st of March.

Using the above array and resolving the issue of a month from now not really existing, or saying a month from now is the number of days equal to the current month, therefore a month from the 31st of January would be the 3rd of March (31 days since Jan. has 31 days). Anyway there are several ways to solve that. After that is solved its pretty trivial algebra.


这篇关于如何在ASP.Net c#中找到42天为1个月1周5天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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