Skip to content

Instantly share code, notes, and snippets.

@mattjohnsonpint
Created April 2, 2014 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattjohnsonpint/9928149 to your computer and use it in GitHub Desktop.
Save mattjohnsonpint/9928149 to your computer and use it in GitHub Desktop.
Answer for SO Q22795924
int days = 678;
// First, you need a starting point
Instant now = SystemClock.Instance.Now;
DateTimeZone timeZone = DateTimeZoneProviders.Bcl.GetSystemDefault(); // or whatever the applicable time zone is
LocalDate today = now.InZone(timeZone).Date;
// then just add the number of days
LocalDate future = today.PlusDays(days);
// and obtain a period with the units desired
Period period = Period.Between(today, future, PeriodUnits.YearMonthDay);
Console.WriteLine("{0} years, {1} months, {2} days", period.Years, period.Months, period.Days);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment