计算平均日期 [英] Calculate Average Date

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

问题描述

大家好


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

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

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

开始日期结束日期

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.

推荐答案

史蒂夫,


对于其中一种语言群体来说,这是一个很好的问题


microsoft.public.dotnet.languages.csharp



microsoft.public.dotnet.languages.vb


他们在这些团体中吃这些东西。


Cor
Hi Steve,

This is a fine question for one of the languages groups

microsoft.public.dotnet.languages.csharp
and
microsoft.public.dotnet.languages.vb

They eat this stuff in those groups.

Cor


Hi Cor


我认为这个问题与语言无关,但是如果你认为我会得到这些小组更好/更快的回复,我会再次发布

那里。 br />

谢谢。

史蒂夫。


" Cor" < no*@non.com>在消息中写道

新闻:eY ************** @ TK2MSFTNGP11.phx.gbl ...
Hi Cor

I thought that this question would be language independant, but if you think
I will get a better/quicker response from these groups I will post it again
there.

Thank you.
Steve.

"Cor" <no*@non.com> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...
嗨Steve,

对于其中一个语言组来说这是一个很好的问题

microsoft.public.dotnet.languages.csharp

microsoft.public.dotnet.languages .vb

他们在这些团体中吃这些东西。

Cor
Hi Steve,

This is a fine question for one of the languages groups

microsoft.public.dotnet.languages.csharp
and
microsoft.public.dotnet.languages.vb

They eat this stuff in those groups.

Cor



Steve< stevea@centurion-ms_RemoveThis_.co.uk>写道:
Steve <stevea@centurion-ms_RemoveThis_.co.uk> wrote:
如果给出一堆日期,我怎样才能找到平均日期?对于
示例,我想查找以下日期的平均时间长度:
------------------------- ---------------------------
开始日期结束日期
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次入场)
平均值= ??
----------- ------------------------------------------
另外,我有计算两个日期之间的时差的函数,
但是如果你使用int account几个月就没有那么好,是不是任何人都有一个好的函数可以接受2个日期参数并返回
时间差格式为''?几个月?天 ?分钟 ?小时 ?秒''
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''




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

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

运算符从

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


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

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

新值。


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

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

运算符)。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

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



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


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

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