nodatime

Converting between time zones with Noda Time

*爱你&永不变心* 提交于 2019-11-29 12:17:12
问题 I'm currently trying to ensure that our legacy back-end can support resolving date times based on the user's current time zone (or, more specifically offset). Our servers are in eastern standard time, and most of our date times originate there. However, for users that are in other time zones, a conversion to their time zone (or, in this case, offset) is needed when retrieving those date times. Also, date times coming from the user will have to be converted to eastern standard time before

Getting Daylight Savings Time Start and End in NodaTime

家住魔仙堡 提交于 2019-11-29 01:59:24
How can I get the starting and ending dates for Daylight Savings Time using Noda Time? The function below accomplishes this task but it is horribly unwieldy and is begging for a simpler solution. /// <summary> /// Gets the start and end of daylight savings time in a given time zone /// </summary> /// <param name="tz">The time zone in question</param> /// <returns>A tuple indicating the start and end of DST</returns> /// <remarks>Assumes this zone has daylight savings time</remarks> private Tuple<LocalDateTime, LocalDateTime> GetZoneStartAndEnd(DateTimeZone tz) { int thisYear = TimeUtils

Comparing LocalDateTime for Different Time Zones in Nodatime

放肆的年华 提交于 2019-11-28 14:01:44
I am working on an application that allows a user to schedule an event. The user supplies an Olson time zone by using a Time Zone Picker , and a date and time for said event through an asp calendar picker and third-party ajax time picker (so the DateTime supplied will always be in the same pattern). I compare the time the user wants and the time zone the user supplies with our server's time and its time zone, and fire the event the instant the user expects it to be fired. From what I understand, having read this link at the nodatime google group , converting one ZonedDateTime to another time

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

丶灬走出姿态 提交于 2019-11-28 13:29:42
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? 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.Zone.GetZoneInterval(instant); return zoneInterval.Savings != Offset.Zero; } Now you can do: zdt

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

拈花ヽ惹草 提交于 2019-11-28 06:29:12
问题 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

DateTime.Now and Culture/Timezone specific

こ雲淡風輕ζ 提交于 2019-11-28 03:50:39
Our application was designed to handle user from different Geographic location. We are unable to detect what is the current end user local time and time zone operate on it. They select different culture like sv-se, en-us, ta-In even they access from Europe/London timezone.. We hosted it in a hosting server in US, application users are from Norway/Denmark/Sweden/UK/USA/India The problem is we used DateTime.Now to store the record created/updated date, etc. Since the Server runs in USA all user data are saved as US time :( After researching in SO, we decided to stored all history dates in DB as

Getting Daylight Savings Time Start and End in NodaTime

岁酱吖の 提交于 2019-11-27 21:46:33
问题 How can I get the starting and ending dates for Daylight Savings Time using Noda Time? The function below accomplishes this task but it is horribly unwieldy and is begging for a simpler solution. /// <summary> /// Gets the start and end of daylight savings time in a given time zone /// </summary> /// <param name="tz">The time zone in question</param> /// <returns>A tuple indicating the start and end of DST</returns> /// <remarks>Assumes this zone has daylight savings time</remarks> private

How can NodaTime be used with EF Code First?

风格不统一 提交于 2019-11-27 17:52:00
I really want to be able to use NodaTime in my Entity Framework Code First database projects but haven't found a "clean" way to do it. What I really want to do is this: public class Photoshoot { public Guid PhotoshootId{get; set;} public LocalDate ShootDate{get; set;} //ef ignores this property } Is there any supported or recommended approach to using NodaTime with EF Code First? Until custom primitive type persistence is natively supported in Entity Framework, a common work around is to use buddy properties . For each custom primitive within your domain model, you create an associated mapped

How does DateTimeOffset deal with daylight saving time?

大憨熊 提交于 2019-11-27 11:57:01
I know that DateTimeOffset stores a UTC date/time and an offset. I also know from this MSDN blog entry that DateTimeOffset should be used to "Work with daylight saving times". What I'm struggling to understand is exactly how DateTimeOffset "work(s) with daylight saving times". My understanding, little that there is, is that daylight saving times are a political decision and cannot be inferred from purely an offset. How can it be that this structure is DST friendly if it only stores an offset? I gather there may be a way to use the TimeZoneInfo class in conjunction with DateTimeOffset. How

Comparing LocalDateTime for Different Time Zones in Nodatime

爷,独闯天下 提交于 2019-11-27 08:08:08
问题 I am working on an application that allows a user to schedule an event. The user supplies an Olson time zone by using a Time Zone Picker, and a date and time for said event through an asp calendar picker and third-party ajax time picker (so the DateTime supplied will always be in the same pattern). I compare the time the user wants and the time zone the user supplies with our server's time and its time zone, and fire the event the instant the user expects it to be fired. From what I