与野田时间的日期差是正确的吗? [英] Date difference from Noda Time is correct?

查看:257
本文介绍了与野田时间的日期差是正确的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTime dtStart = new DateTime(2015,7,28);
LocalDate ldtStart = LocalDate.FromDateTime(dtStart);

DateTime dtEnd = new DateTime(2017, 2, 1);
LocalDate ldtEnd = LocalDate.FromDateTime(dtEnd);

Period period = Period.Between(ldtStart, ldtEnd, PeriodUnits.YearMonthDay);

以上结果:

年。 -> 1

期限。月份-> 6

期限。天-> 4

Result for above:
period.Years -> 1
period.Months -> 6
period.Days -> 4

您可以看到我从Noda时间库获得的区别。

但是我得到 https://www.easycalculation.com/date-day/age-calculator.php

以上链接的结果:

1年,6个月和1天

As you can see the difference i got from Noda Time library.
But i get different result for https://www.easycalculation.com/date-day/age-calculator.php
Result for above link:
1 years, 6 months, and 1 days

开始日期:2015年7月28日

结束日期:2017年2月1日

Start Date: 28th July 2015
End Date: 1st Feb 2017

有人可以告诉我,我从noda时间插件获得的结果比链接我更准确

Can someone please tell me that the result i got from noda time plugin is more accurate then the link I provided?

推荐答案

更准确要求您详细说明如何计算差异。这里没有一个正确的答案。根据记录,Noda Time在元素方面起作用。因此,如果您在2015年7月28日之前加上1年零6个月零4天,则会得到:

"More accurate" requires a specification of how you want to compute the difference. There's no single right answer here. As documented, Noda Time works element-wise. So if you add 1 year, 6 months and 4 days to 28th July 2015 you get:


  • 加上1年:2016年7月28日

  • 添加6个月:2017年1月28日

  • 添加4天:2017年2月1日

该网站使用的代码是网站本身

The code used for the site is available on the site itself. It looks like that's taking a rather more naïve approach.

特别是,如果您询问在2017年1月31日出生的人在2017年2月1日的年龄,他们会说他们已经两岁了。我认为那是不对的...

In particular, if you ask it how old someone born on January 31st 2017 is on February 1st 2017, they'll say they're -2 days old. I don't think that's right...

这篇关于与野田时间的日期差是正确的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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