计算平均日期

扫码查看
本文介绍了计算平均日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


如果给出一堆日期,我怎样才能找到平均日期?对于

的例子,我想找到以下日期的平均时间长度:

----------------- -----------------------------------

开始日期结束日期

01/01/2004 12:50 pm 02/01/2004 18:40 pm

02/01/2004 13:40 pm 02/01/2004 13:57 pm

02/01/2004 14:30 pm 02/01/2004 19:50 pm


最小= 17分钟(第2次入场)

最大= 1第5天10分钟(第1次入场)

平均= ??

--------------------- --------------------------------

另外,我有一个计算时间的函数两个日期之间的差异,

但是如果你花费几个月的话,它就不能很好地工作了吗?

任何人都有一个好的功能可以带2个日期参数并返回格式为''的

时差?几个月?天 ?分钟 ?小时 ?秒钟''


感谢您的帮助,


亲切的问候,

史蒂夫。

Hi all

How would I find out the average date when given a bunch of dates? For
example, I want to find the average length in time from the following dates:
----------------------------------------------------
Start Date End Date
01/01/2004 12:50pm 02/01/2004 18:40pm
02/01/2004 13:40pm 02/01/2004 13:57pm
02/01/2004 14:30pm 02/01/2004 19:50pm

Min = 17 Minutes (2nd entry)
Max = 1 Day 5 Hours 10 Minutes (1st entry)
Average = ??
-----------------------------------------------------
Also, I have a function that calculates the time difference between 2 dates,
but it doesn''t work all that well if you take int account months, does
anyone have a good function that can take 2 date parameters and return the
time difference formatted as ''? Months ? Days ? Minutes ? Hours ? Seconds''

Thanks for your help,

Kind Regards,
Steve.

推荐答案







听起来你实际上是在平均一堆

* timepans *之后。您可以通过使用减去方法或(在C#中)使用 - "

运算符从

另一个减去一个DateTime来创建TimeSpan。 (例如TimeSpan diff = end-start;)


然后你可以(例如)在每个时间段内添加刻度数,

除以数字时间跨度,然后创建一个新的时间跨度

新值。


您可以以与其他任何方式相同的方式找到最小值/最大值,只需

使用比较(使用CompareTo或(在C#中)比较

运算符)。


-

Jon Skeet - < sk *** @ pobox.com>


如果回复小组,请不要给我发邮件



It sounds like you''re actually after the average of a bunch of
*timespans*. You create a TimeSpan by subtracting one DateTime from
another, either using the Subtract method or (in C#) using the "-"
operator. (eg TimeSpan diff = end-start; )

You could then (for instance) add the number of ticks in each timespan,
divide by the number of timespans, and then create a new timespan for
the new value.

You can find the min/max in the same way as for anything else, just
using comparisons (either using CompareTo or (in C#) the comparison
operators).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于计算平均日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 05:20
查看更多