Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. using NodaTime;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //Get now from system clock (this is an Instant)
  10. var now = SystemClock.Instance.Now;
  11.  
  12. //get zoned datetime of now
  13. var ztNow = new ZonedDateTime(now, DateTimeZone.Utc);
  14.  
  15. //now minus 8 months period converted to local datetime
  16. var ltBeforePeriod = ztNow.LocalDateTime.Minus(Period.FromMonths(8));
  17.  
  18. //Get zoned date time in utc
  19. var ztBeforePeriod = ltBeforePeriod.InUtc();
  20.  
  21. //or convert it to your zone
  22. //ltAfterPeriod.InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull("your zone id"));
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement