nodatime

Date difference from Noda Time is correct?

故事扮演 提交于 2019-12-12 21:05:59
问题 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); Result for above: period.Years -> 1 period.Months -> 6 period.Days -> 4 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

NodaTime: Time zone related issue using NodaTime library c#

蹲街弑〆低调 提交于 2019-12-12 10:31:37
问题 here i am giving my code and what happen. when i am passing timezone id to .net time zone that works the code as below var zoneId = "India Standard Time"; var zone = TimeZoneInfo.FindSystemTimeZoneById(zoneId); var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zone); string xx1 = now.ToLongTimeString(); when i am passing the same time zone id India Standard Time to noda time library then i am getting error "Time zone India Standard Time is unknown to source TZDB: 2014e (mapping: 9723

Equivalent of joda LocalTime getMillisOfDay() in noda

不问归期 提交于 2019-12-12 03:41:33
问题 I am porting some code from Java to .NET and looking for a noda-time equivalent of the getMillisOfDay() joda-time method of the LocalTime object. Is there an equivalent one or must I code my own? 回答1: In Noda Time 1.x, use the LocalTime.TickOfDay property, and then just divide it by NodaConstants.TicksPerMillisecond to get milliseconds: LocalTime localTime = ...; long millis = localTime.TickOfDay / NodaConstants.TicksPerMillisecond; 回答2: Closest you can get to the number of milliseconds since

NodaTime: From server to client

烂漫一生 提交于 2019-12-11 09:17:41
问题 I am using NodaTime I am storing time information in the form of Ticks since epoch. However, I want to pass the number of milliseconds since unix epoch back to the client browser, so I can construct a javascript Date() object. Is there not a way to do this? If this method is out of the question, does anyone else have a better idea? p.s. I'm tired of messing with strings because I always have to wonder how they will be interpreted. 回答1: There are 10 000 ticks per millisecond, and NodaTime has

how to use nodatime for persian in c#?

穿精又带淫゛_ 提交于 2019-12-11 08:33:19
问题 nodatime 1.3 released , but i want to use nodatime in c# for Persian date time . how can i show Persian date time with Noda Time? var london = DateTimeZoneProviders.Tzdb["Europe/London"];" What must I do for Persian? 回答1: You need to explicitly use the Persian calendar. For example: var calendar = CalendarSystem.GetPersianCalendar(); var zone = DateTimeZoneProviders.Tzdb["Europe/London"]; var now = SystemClock.Instance.Now.InZone(zone, calendar); // Now you can get the month, etc. Or to

Create Instant using a negative year

被刻印的时光 ゝ 提交于 2019-12-10 19:51:26
问题 I am trying to create an Instant based upon a B.C.E. year in the Gregorian calendar. Here is what I have so far: Instant.FromDateTimeOffset(new DateTimeOffset(-1000, 10, 01, 0, 0, 0, 0, new System.Globalization.GregorianCalendar(), new TimeSpan())); I get the error: An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Year, Month, and Day parameters describe an un-representable DateTime. Edit Doing some research on NodaTime , I

Nodatime calculation of years/months/days in X days

你。 提交于 2019-12-10 18:03:16
问题 Say I have 678 days, how to calculate how many years, months and days are there from that moment? 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); 回答1: You just need to add the number of days to the

Errors Creating App Package (UWP, Appx) - fatal error CMF1106: failed to open input PDB file for reading

只谈情不闲聊 提交于 2019-12-10 17:18:52
问题 I'm getting errors when Creating App Packages for a UWP Win 10 application. On my machine the error is: C:\Users\Developer\.nuget\packages\nodatime\2.4.0\lib\netstandard2.0\NodaTime.pdb : fatal error CMF1106: failed to open input PDB file for reading (PDB error code = 11)3 input PDB file is not generated by /DEBUG:fastlinkW must read and agree to the Data Collection Policy at MSPDBCMF : fatal error CMF1000: internal error The pdb file exists in the mentioned directory: C:\Users\Developer\

Noda Time: Period.Between() returning incorrect number of days?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 17:18:31
问题 Given the code snippet below, why are the final four output periods the same? I would expect the Days portion for those lines to be 4, 3, 2, 1 not 4, 4, 4, 4. Is this a bug or am I missing something obvious? (It's late and I'm tired, so it's very possibly the latter.) I'm using Noda Time 1.2.0. for (int day = 25; day <= 31; day++) { var d1 = new LocalDate(2013, 12, day); var d2 = new LocalDate(2015, 3, 4); var period = Period.Between(d1, d2); Debug.WriteLine("Day: {0}, Period: {1}", day,

use NodaTime to calculate an inclusive days period

ε祈祈猫儿з 提交于 2019-12-10 13:25:07
问题 So for example if I have the following code: var nodaStart = new LocalDate(2012, 5, 1); var nodaEnd = new LocalDate(2012,5,2); var daysBetween = Period.Between(nodaStart, nodaEnd,PeriodUnits.Day); Then daysBetween.Days == 1 However, the range I calculate needs to count that as 2 days. i.e. it needs to be inclusive of the start and end date. The actual method can take and start and end date (that are no more than a year apart) and needs to calculate the number of days. If there are more than