nodatime

Determine how to calculate times across different timezones using nodaTime and withZone on ZoneDateTime

强颜欢笑 提交于 2019-12-02 06:28:04
问题 When converting times between time zones. I found the follow code works. However I am not sure how programmatically what to put as my offset for the constructor for the ZonedDateTime . I had a choice of one of the offsets on zoneChicago, which is just two, because its either with our without daylight savings, but how do I know which one I use, and for timezones that have more then just two, what is the best way to populate that offset? Thanks, Jim var zoneLA = c.GetZoneOrNull("America/Los

Determine how to calculate times across different timezones using nodaTime and withZone on ZoneDateTime

折月煮酒 提交于 2019-12-02 02:42:42
When converting times between time zones. I found the follow code works. However I am not sure how programmatically what to put as my offset for the constructor for the ZonedDateTime . I had a choice of one of the offsets on zoneChicago, which is just two, because its either with our without daylight savings, but how do I know which one I use, and for timezones that have more then just two, what is the best way to populate that offset? Thanks, Jim var zoneLA = c.GetZoneOrNull("America/Los_Angeles"); var zoneChicago = c.GetZoneOrNull("America/Chicago"); var zdtChicago = new ZonedDateTime(

Posting models with NodaTime auto-props to WebAPI

ぃ、小莉子 提交于 2019-12-01 18:55:58
We are in the process of using NodaTime for time / date models in our project. The project is a web application, using WebAPI. When attempting to post a model containing LocalTime autoprops, we receive an InsufficientExecutionStackException. In order to isolate our project from this issue, I created a new WebAPI project. Using NuGet, I added NodaTime and NodaTime.Serialization.JsonNet to the project. In Startup.cs , I used ConfigureForNodaTime as such: GlobalConfiguration.Configure(x => { x.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); x.Formatters.JsonFormatter.SerializerSettings

Posting models with NodaTime auto-props to WebAPI

不想你离开。 提交于 2019-12-01 18:53:25
问题 We are in the process of using NodaTime for time / date models in our project. The project is a web application, using WebAPI. When attempting to post a model containing LocalTime autoprops, we receive an InsufficientExecutionStackException. In order to isolate our project from this issue, I created a new WebAPI project. Using NuGet, I added NodaTime and NodaTime.Serialization.JsonNet to the project. In Startup.cs , I used ConfigureForNodaTime as such: GlobalConfiguration.Configure(x => { x

LocalDate from Week and WeekYear

◇◆丶佛笑我妖孽 提交于 2019-12-01 17:40:15
Using the NodaTime library, how can I calculate a LocalDate of the first day of the week based on a Week number and week WeekYear. The reverse of this: var date = new LocalDate(2012, 1, 1); int weekYear = date.WeekYear; // 2011 int weekNr = date.WeekOfWeekYear; // 52 Something like this fake code: var newDate = LocalDate.FirstDayFromWeek(weekYear, weekNr); Firstly, you should be looking at how to construct the relevant LocalDate - that's all the information you logically have if you've got a WeekYear and WeekOfWeekYear . You can then get a LocalDateTime from a LocalDate with AtMidnight if you

LocalDate from Week and WeekYear

蹲街弑〆低调 提交于 2019-12-01 16:17:03
问题 Using the NodaTime library, how can I calculate a LocalDate of the first day of the week based on a Week number and week WeekYear. The reverse of this: var date = new LocalDate(2012, 1, 1); int weekYear = date.WeekYear; // 2011 int weekNr = date.WeekOfWeekYear; // 52 Something like this fake code: var newDate = LocalDate.FirstDayFromWeek(weekYear, weekNr); 回答1: Firstly, you should be looking at how to construct the relevant LocalDate - that's all the information you logically have if you've

Is there a concept of working-days in the Nodatime library?

百般思念 提交于 2019-12-01 13:26:38
Is there a concept of working-days in the Nodatime library? What I would like to do is to somehow state that there is 5 working-days in a calender week, and then be able to ask something like: From [any given date] + 10 working-days what is the end date? or From [this calender date] to [that calender date] how many working-days are in that interval? No, this doesn't exist as you described it. However, you can certainly use Noda Time's LocalDate object and implement your own logic. An O(n) implementation would simply use LocalDate.DayOfWeek and a for loop. I'm sure one could create an O(1)

Noda Time - Start/end of day with zone

僤鯓⒐⒋嵵緔 提交于 2019-11-30 13:59:40
问题 What's the proper and more concise way to get the ZonedDateTime(s) which represent the start and the end of the current day in the timezone set on the system on which the code runs? Isn't the following code too much complicated? ZonedDateTime nowInZone = SystemClock.Instance.Now.InZone(DateTimeZoneProviders.Bcl.GetSystemDefault()); ZonedDateTime start = new LocalDateTime(nowInZone.Year, nowInZone.Month, nowInZone.Day, 0, 0, 0).InZoneStrictly(DateTimeZoneProviders.Bcl.GetSystemDefault());

Noda Time - Start/end of day with zone

社会主义新天地 提交于 2019-11-30 09:00:26
What's the proper and more concise way to get the ZonedDateTime(s) which represent the start and the end of the current day in the timezone set on the system on which the code runs? Isn't the following code too much complicated? ZonedDateTime nowInZone = SystemClock.Instance.Now.InZone(DateTimeZoneProviders.Bcl.GetSystemDefault()); ZonedDateTime start = new LocalDateTime(nowInZone.Year, nowInZone.Month, nowInZone.Day, 0, 0, 0).InZoneStrictly(DateTimeZoneProviders.Bcl.GetSystemDefault()); ZonedDateTime end = new LocalDateTime(nowInZone.Year, nowInZone.Month, nowInZone.Day, 23, 59, 59)

How Convert UTC Date & time to local time using different timezone Nodatime

折月煮酒 提交于 2019-11-29 12:27:30
i am using a function which is taking date time over the internet from external server. here is the function which i am using to get date and time without depend on user pc date time settings. using NodaTime; using NodaTime.Text; using System.IO; using System.Globalization; public static DateTime GetFastestNISTDate() { var result = DateTime.MinValue; DateTime utcDateTime = DateTime.MinValue; // Initialize the list of NIST time servers // http://tf.nist.gov/tf-cgi/servers.cgi string[] servers = new string[] { "nist1-ny.ustiming.org", "nist1-nj.ustiming.org", "nist1-pa.ustiming.org", "time-a