【发布时间】:2014-05-12 19:40:20
【问题描述】:
假设我有678天,如何计算从那一刻起有多少年、多少月、多少天?
Duration duration = Duration.FromStandardDays(678);
Instant now = SystemClock.Instance.Now;
Instant future = now + duration;
// I have to convert NodaTime.Instant to NodaTime.LocalDate but don't know how
Period period = Period.Between(now, future);
Console.WriteLine("{0} years, {1} months, {2} days", period.Years, period.Months, period.Days);
【问题讨论】:
-
您的意思是您还有 678 天的时间来计算时间结束的时间?更严重的是,请参阅How to convert number of days to years,months and days、Calculate days in years and months?、Calculating Day, Month, Year 或尝试使用搜索。
-
你不能没有参考点。一年是可变长度的,一个月也是如此。所以答案取决于你问它的日期。
-
@Code 678 天 = 1 年 10 个月 x 天。这就是我需要的。
-
@spender 没错,开始日期就是计算的时刻。
-
视情况而定。有闰年吗?我们需要更多信息。