Questions tagged [nodatime]

Noda Time is a .NET library designed to simplify the correct handling of dates and times in the .NET environment.

Noda Time is an alternative date and time API for .NET. It helps you to think about your data more clearly, and express operations on that data more precisely.

It borrows many concepts from Joda Time, the industry standard date and time handling library for Java. It is an idiomatic port - not a direct translation. It has been specifically tailored for use in the .Net Framework.

There are many reasons to use Noda Time instead of the normal BCL date and time types, including:

  • Support for IANA/Olson time zones such as America/New_York.

  • Distinct representations of different concepts: Instead of using DateTime to represent everything, there are different types for dates, times, values with time zones, values with just UTC offsets, etc.

  • Reduced surprise: All Noda Time types work consistently in a predictable manner. By contrast, the DateTime type has different behaviors depending on its Kind property. For examples of the type of surprises that are avoided, read "What's Wrong with DateTime Anyway?"

  • Testability: You can easily mock the system clock using the IClock interface, and you have to go out of your way if you want to be affected by the computer's local time zone. By contrast, DateTime.Now is difficult to mock, and is bound to the system time zone by default.

Noda Time also has the ability to work with Windows time zones, and can convert between them. It also contains zone.tab data, which can be used to correlate time zones with a country code, or locate time zones on a map.

Resources:

The primary author of Noda Time is Jon Skeet, of Stack Overflow fame.

See also:

452 questions
6
votes
1 answer

Using NodaTime to convert invalid (skipped) datetime values to UTC

What I want to accomplish is to convert a DateTime (parsed from a string assumed to be in EST/EDT) to UTC. I am using NodaTime because I need to use Olson timezones. Converting an invalid (skipped) DateTime to UTC using NodaTime's…
ash
  • 236
  • 1
  • 7
6
votes
2 answers

Serialize NodaTime JSON

I am making a prototype project of NodaTime compared to BCL's DateTime, but executing this result gives me recursionLimit exceeded error. This is the function I am using to JSONify my viewmodel. The error happens after this function returns. …
mac10688
  • 2,145
  • 2
  • 24
  • 37
6
votes
1 answer

DateTimeZone to/from database

I'm trying to get a handle on using the Noda Time framework by Jon Skeet (and others). How do I store the DateTimeZone and retrieve it from the database. I thought the Id property value might be the one to set to the database, but how do I create…
Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
6
votes
1 answer

Is it safe to store time zone ids in a database or can they change?

I have just started working with NodaTime. In my app, the user creates an event and chooses a time zone. Regardless of whether I use the BCL (Windows) time zone list or the TZDB (Olson) list (and do not mix them!), I need to persist the id of the…
Rob Kent
  • 5,183
  • 4
  • 33
  • 54
6
votes
2 answers

use NodaTime to calculate an inclusive days period

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…
Paul D'Ambra
  • 7,629
  • 3
  • 51
  • 96
5
votes
1 answer

Filtering using a DateTimeOffset as a parameter issue

I was playing with dates using a C# program. I want to filter on any table that has a DateTime, DateTime2, DateTimeOffset columns. I store the LastRefreshDate as DateTimeOffSet in UTC and I use it to filter data on those tables. I adjust the offset…
billybob
  • 2,859
  • 6
  • 35
  • 55
5
votes
1 answer

Rounding Time with NodaTime

I have some LocalDateTimes where I need to round the time of day up/down to the nearest minute number according to a list of defined minutes. For instance, if I have the datetime 2018-03-20T12:13:47 and I have to round it to the next half hour (so…
Mikkel R. Lund
  • 2,336
  • 1
  • 31
  • 44
5
votes
0 answers

How to filter deprecated time zones with NodaTime?

I would like to return to users the list of active (non-deprecated) time zone Ids. Using TzdbDateTimeZoneSource.Default.ZoneLocations.ToList() I can list all Time Zones, but I didn't find how to filter out the deprecated zones. In a worst case I…
Zoltan Tirinda
  • 769
  • 8
  • 25
5
votes
1 answer

OffsetTime in NodaTime

I'm looking for some kind of OffsetTime support in NodaTime, but am not seeing anything. I am receiving data in a format such as "17:13:00+10:00". I am to treat this as a time offset, applying it to a given date (which the user is in control of) to…
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
5
votes
2 answers

Convert specific country date time to UTC with NodaTime

I would like to convert specific date time value to UTC with NodaTime by giving country code. For example country is Turkey, country code is TR and specific date time is "Feb 5, 2016 7:45 PM" it would be "Feb 5, 2016 5:45 PM" is it possible? Also…
Kerberos
  • 331
  • 1
  • 11
5
votes
1 answer

How to validate an IANA string with nodatime?

var easternTimeZone = DateTimeZoneProviders.Tzdb[timeZoneIdentifier]; Using NodaTime how should I validate that when the string timeZoneIdentifier is set to a valid IANA string like "Europe/Stockholm" it is deemed valid but an unsupported IANA…
Dizzle
  • 1,026
  • 13
  • 26
5
votes
1 answer

Output an ISO 8601 string

How do we create a date/time in a specific timezone and output a short ISO 8601 date/time with offset from UTC? For instance, 5 PM Pacific Standard Time on 08 September 2015 must look like this: 2015-09-08T17:00:00-07:00 Here is my current…
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
5
votes
1 answer

Persisting Nodatime Instant in SQL Server with ServiceStack / OrmLite

I'm using NodaTime Instant for date/time storage in my DTOs with ServiceStack. I have specified the SQL type in the DTO as datetimeoffset, and ServiceStack correctly creates the table with that type. However, upon saving, I get an…
Josh Anderson
  • 5,975
  • 2
  • 35
  • 48
5
votes
1 answer

With NodaTime, how do I format a ZonedDateTime in current culture

I have a ZonedDateTime and I want to display it such that the datetime is formatted with the short date and short time configured on the workstation followed by the offset (something like... 05/01/2005 02:30 PM -05:00). I expected something like…
Art L.
  • 53
  • 2
5
votes
1 answer

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

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…
aman shivhare
  • 334
  • 2
  • 13