nodatime

Long form name of timezone in NodaTime

走远了吗. 提交于 2019-12-30 18:50:32
问题 In NodaTime, how do you find the long form name of a timezone given the tz timezone id? For example, if I supply "America/Los_Angeles", I should get "Pacific Standard Time" back. 回答1: The information you need to produce the "long form" of a time zone name isn't in Noda Time, but it can be found in the CLDR. I've recently put together a library called simply "Time Zone Names", that embeds the CLDR time zone names. You can use these with the IANA (TZDB) identifiers that are used by Noda Time

Difference Between DateTime (UTC) Based on a Local Timezone

一曲冷凌霜 提交于 2019-12-25 19:05:20
问题 I have two DateTime objects which contain two UTC date/times and a users TimezoneId (tzdb) as a string . I'm trying to write a method that takes these three parameters and returns the total seconds (or Duration ) between the two datetimes relative to the timezone. public static double GetDurationForTimezone(DateTime startUtc, DateTime endUtc, string timezoneId) { var timezone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(timezoneId); // convert UTC to timezone var startInstantUtc = Instant

Parsing DateTime string using NodaTime

纵然是瞬间 提交于 2019-12-24 23:23:27
问题 How can we parse a Zoned DateTime string using NodaTime? I am currently using LocalDateTimePattern for parsing, but I think that the DateTime value yielded would be in the Server's timezone. var pattern = LocalDateTimePattern.CreateWithInvariantCulture(dateTimePattern); var parseResult = pattern.Parse(dateTimeString); if (!parseResult.Success) { // throw an exception or whatever you want to do } I came across ZonedDateTime pattern when I was looking at the Noda Time API. But, I am not able to

ShouldBeEquivalentTo failing for equivalent objects when the subject is a DateTime

只愿长相守 提交于 2019-12-24 15:32:05
问题 What I'm trying to do I've just set up a test to ensure that a NodaTime LocalDateTime is mapped to a .NET DateTime , retaining the same date and time values. I'm using FluentAssertions' ShouldBeEquivalentTo method to compare the corresponding property values. [TestClass] public class LocalDateTimeMapping { [TestMethod] public void RetainsComponentValues() { var nodatimeTime = new LocalDateTime(); var dotnetTime = nodatimeTime.ToDateTimeUnspecified(); dotnetTime.ShouldBeEquivalentTo

Parse DateTime string into Noda Time LocalDateTime in a forgiving way?

限于喜欢 提交于 2019-12-24 08:49:43
问题 I have GetDateTimeOffset(string latitude, string longitude, string dateTime) web service which determines Time Offset given Lat/Long and local DateTime. Our current client web page uses DateTimePicker plugin http://trentrichardson.com/examples/timepicker/. We use the default date formatting and format time part as 'h:mm:ss TT Z' so a string we pass to a server looks like '01/22/2014 12:09:00 AM -05:00'. But I'm thinking about making our web service more generic, so it should be forgiving for

how to convert ticks to momentjs object

試著忘記壹切 提交于 2019-12-24 00:15:51
问题 I'm using nodatime and it returns ticks. How can I convert ticks to use and format using momentjs? public JsonResult Foo() { var now = SystemClock.Instance.Now.Ticks; return Json(now, JsonRequestBehavior.AllowGet); } it returns long such as 14598788048897648 . 回答1: Don't leak Ticks out of your API. Instead, use the NodaTime.Serialization.JsonNet package to allow NodaTime types like Instant to be serialized in ISO8601 standard format. That format is supported natively in moment.js. See the

Getting Started with Noda Time

ε祈祈猫儿з 提交于 2019-12-20 08:48:33
问题 I am looking to use Noda time for a fairly simple application, however I am struggling to find any documentation to handle a very basic use case: I have a logged in user, and will be storing their preferred timezone in the settings. Any date/times that come from the client come in a known text format (e.g. "dd/MM/yyyy HH:mm"), with a known time zone id (e.g. "Europe/London"). I was planning on converting these times to UTC/Noda Instants to prevent the need to store the time zone info with

What is the System.TimeZoneInfo.IsDaylightSavingTime equivalent in NodaTime?

泄露秘密 提交于 2019-12-17 20:49:47
问题 System.TimeZoneInfo has a method called IsDaylightSavingTime, which takes a DateTime object and returns true if the specified datetime falls in the DST for that timezone. Is there an equivalent function in NodaTime or another way to achieve the same result? 回答1: You can get this from a ZoneInterval . Here is an extension method that will help. public static bool IsDaylightSavingsTime(this ZonedDateTime zonedDateTime) { var instant = zonedDateTime.ToInstant(); var zoneInterval = zonedDateTime

Working with days which don't start at midnight in NodaTime

故事扮演 提交于 2019-12-14 03:52:18
问题 I am working on an application with train schedules, where the first train leaves at 0400 while the last train leaves at 0200. The users of this application therefore deal with days starting at 0300 and ending at 0300. In other words, when they say "The Wednesday-train at 0200" they really mean "The train that leaves on Thursday at 0200". Our application needs to store all of the trains leaving on (for example) Wednesday, which means it should not include the trains that leave before 0300 but

Convert same time to different time zone

谁说胖子不能爱 提交于 2019-12-13 04:03:14
问题 I am trying to convert times to different time zones, but not the way you're thinking. I need to convert a DateTime that is 9am EST to 9am CST on the UTC for example. The timezones are variable so just adding/subtracting hours doesn't seem correct way to do it with NodaTime Fri, 21 Feb 2014 21:00:00 EST = 1393034400 Epoch Timestamp convert to Fri, 21 Feb 2014 21:00:00 CST = 1393030800 Epoch Timestamp 回答1: If I understand the question correctly, it sounds like you're trying to convert a date