nodatime

Convert NodaTime DateTimeZone into TimeZoneInfo

对着背影说爱祢 提交于 2019-12-04 19:09:17
问题 I'm using NodaTime because of its nice support for zoneinfo data, however I have a case where I need to convert the DateTimeZone into TimeZoneInfo for use in Quartz.NET. What's the recommended approach here? IANA has a mapping file between Windows time zones and zoneinfo time zones, can I create an extension method that utilises this information? Thanks, Dean 回答1: I would avoid using reflection if possible. I wouldn't like to bet on your approach working with future versions :) Feel free to

Converting NodaTime to Unix timestamp and the importance of LocalDateTime

二次信任 提交于 2019-12-04 14:49:43
I am currently using NodaTime based on my frustrations dealing with timezones in C#'s DateTime class. So far, I'm really pleased. public static string nodaTimeTest(string input) { var defaultValue = new OffsetDateTime(new LocalDateTime(2000, 1, 1, 0, 0), Offset.Zero); var pattern = OffsetDateTimePattern.Create("yyyy-MM-dd'T'HH:mm:sso<m>", CultureInfo.InvariantCulture, defaultValue); var result = pattern.Parse(input).Value; return result.ToString(); } I have three specific questions. Above is the method I use where I parse in dateTime strings. I have a format string which allows me how to parse

How to convert the standard Noda Timezone Id's from English to Localized Language?

ぃ、小莉子 提交于 2019-12-04 08:55:10
I am currently trying to localize my windowsphone Time App for a few countries. I am using Noda Time as it was extremely easy for a newbie. The problem I am facing that all the Timezone Id's are in standard English and I am searching for a way to get those Id's converted to Local Language strings. One way would be too make Localized strings for each ID in every language. But it seems to be Highly inefficient as there are 500 timezones. Please suggest a way for me to get directly the TimeZone ID's converted into Local Language in a less time consuming way. My code: var now = Instant

Instant.Now for NodaTime

寵の児 提交于 2019-12-04 08:53:19
问题 I'm trying to get a handle on using the Noda Time framework by Jon Skeet (and others). I'm trying to store the current now(Instant). Instant is created from a long ticks, but what is the current now count of Ticks? Is it: Instant now = new Instant(DateTime.Now.ToUniversalTime().Ticks); And or? Instant now = Instant.FromDateTimeUtc(DateTime.Now.ToUniversalTime()); Are they equivalent, am I even doing this right? PS, if Jon answer's this - I'd like to propose an Instant.Now property. PS2 I know

Deserialize a date query parameter of the form yyyy-MM-dd into a noda time LocalDate object using ASP.NET Web API

冷暖自知 提交于 2019-12-04 03:28:32
I'm investigating the use of NodaTime LocalDate to replace our existing use of of the BCL DateTime/DateTimeOffset classes. We have run into a number of timezone related issues with our code due to our misunderstanding of the arguably ambiguous behavior of DateTime. To fully leverage NodaTime I want to be able to send and receive dates from our ASP.NET Web API 2 web services of the form YYYY-MM-DD. I have had success in properly serializing LocalDate to YYYY-MM-DD. However I am unable to deserialize a date query parameter to a LocalDate. The LocateDate is always 1970-01-01. Here is my current

Create a NodaTime LocalDate representing “today”

人盡茶涼 提交于 2019-12-03 22:37:56
What is the recommended way to create a LocalDate instance that represents "today". I was expecting there to be a static "Now" or "Today" property in the LocalDate class, but there isn't. My current approach is to use DateTime.Now: var now = DateTime.Now; LocalDate today = new LocalDate(now.Year, now.Month, now.Day); Is there a better way? First recognize that when you say "today", the answer could be different for different people in different parts of the world. Therefore, in order to get the current local date, you must have a time zone in mind. Noda Time correctly models this by giving you

Convert NodaTime DateTimeZone into TimeZoneInfo

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 12:27:41
I'm using NodaTime because of its nice support for zoneinfo data, however I have a case where I need to convert the DateTimeZone into TimeZoneInfo for use in Quartz.NET. What's the recommended approach here? IANA has a mapping file between Windows time zones and zoneinfo time zones, can I create an extension method that utilises this information? Thanks, Dean Jon Skeet I would avoid using reflection if possible. I wouldn't like to bet on your approach working with future versions :) Feel free to file a feature request for this functionality for future versions, but for the moment I'd build up

Converting between time zones with Noda Time

ε祈祈猫儿з 提交于 2019-12-03 05:10:18
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 persistence on the server. Given that the front end we are developing is web-based, I am able to retrieve

Instant.Now for NodaTime

≡放荡痞女 提交于 2019-12-03 01:16:15
I'm trying to get a handle on using the Noda Time framework by Jon Skeet (and others). I'm trying to store the current now(Instant). Instant is created from a long ticks, but what is the current now count of Ticks? Is it: Instant now = new Instant(DateTime.Now.ToUniversalTime().Ticks); And or? Instant now = Instant.FromDateTimeUtc(DateTime.Now.ToUniversalTime()); Are they equivalent, am I even doing this right? PS, if Jon answer's this - I'd like to propose an Instant.Now property. PS2 I know the title contains a tag, but it wouldn't let me have a short "Instant.Now" title. Cristian Lupascu I

Getting Started with Noda Time

徘徊边缘 提交于 2019-12-02 17:45:09
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 each date in the database. Firstly, does this sound like a sensible approach? I am free to change pretty