Class DateTimeZone
Represents a time zone - a mapping between UTC and local time. A time zone maps UTC instants to local times
- or, equivalently, to the offset from UTC at any particular instant.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Inheritance
Object
DateTimeZone
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Assembly: NodaTime.dll
Syntax
public abstract class DateTimeZone : IZoneIntervalMapWithMinMax, IZoneIntervalMap
Constructors
DateTimeZone(String, Boolean, Offset, Offset)
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
protected DateTimeZone(string id, bool isFixed, Offset minOffset, Offset maxOffset)
Parameters
Type |
Name |
Description |
String |
id |
The unique id of this time zone. |
Boolean |
isFixed |
Set to true if this time zone has no transitions. |
Offset |
minOffset |
Minimum offset applied within this zone |
Offset |
maxOffset |
Maximum offset applied within this zone |
Exceptions
Type |
Condition |
ArgumentNullException |
id is null. |
Properties
Id
Get the provider's ID for the time zone.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public string Id { get; }
Property Value
Type |
Description |
String |
The provider's ID for the time zone. (The value returned is never null.) |
MaxOffset
Gets the greatest (most positive) offset within this time zone, over all time.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public Offset MaxOffset { get; }
Property Value
Type |
Description |
Offset |
The greatest (most positive) offset within this time zone, over all time. |
MinOffset
Gets the least (most negative) offset within this time zone, over all time.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public Offset MinOffset { get; }
Property Value
Type |
Description |
Offset |
The least (most negative) offset within this time zone, over all time. |
Utc
Gets the UTC (Coordinated Universal Time) time zone.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public static DateTimeZone Utc { get; }
Property Value
Methods
AtLeniently(LocalDateTime)
Maps the given
LocalDateTime to the corresponding
ZonedDateTime in a lenient
manner: ambiguous values map to the earlier of the alternatives, and "skipped" values are shifted forward
by the duration of the "gap".
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public ZonedDateTime AtLeniently(LocalDateTime localDateTime)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
The local date/time to map. |
Returns
Type |
Description |
ZonedDateTime |
The unambiguous mapping if there is one, the earlier result if the mapping is ambiguous,
or the forward-shifted value if the given local date/time is skipped. |
AtStartOfDay(LocalDate)
Returns the earliest valid
ZonedDateTime with the given local date.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public ZonedDateTime AtStartOfDay(LocalDate date)
Parameters
Type |
Name |
Description |
LocalDate |
date |
The local date to map in this time zone. |
Returns
Exceptions
Type |
Condition |
SkippedTimeException |
The entire day was skipped due to a very large time zone transition.
(This is extremely rare.) |
AtStrictly(LocalDateTime)
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public ZonedDateTime AtStrictly(LocalDateTime localDateTime)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
The local date and time to map into this time zone. |
Returns
Sample snippet
using NodaTime;
using System;
DateTimeZone dublin = DateTimeZoneProviders.Tzdb["Europe/Dublin"];
ZonedDateTime dt = dublin.AtStrictly(new LocalDateTime(2010, 6, 9, 15, 15, 0));
Console.WriteLine(dt.Hour);
Console.WriteLine(dt.Year);
Instant instant = Instant.FromUtc(2010, 6, 9, 14, 15, 0);
Console.WriteLine(dt.ToInstant());
Output:
15
2010
2010-06-09T14:15:00Z
Exceptions
ForOffset(Offset)
Returns a fixed time zone with the given offset.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public static DateTimeZone ForOffset(Offset offset)
Parameters
Type |
Name |
Description |
Offset |
offset |
The offset for the returned time zone |
Returns
Type |
Description |
DateTimeZone |
A fixed time zone with the given offset. (The value returned is never null.) |
GetUtcOffset(Instant)
Returns the offset from UTC, where a positive duration indicates that local time is
later than UTC. In other words, local time = UTC + offset.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public virtual Offset GetUtcOffset(Instant instant)
Parameters
Type |
Name |
Description |
Instant |
instant |
The instant for which to calculate the offset. |
Returns
Type |
Description |
Offset |
The offset from UTC at the specified instant.
|
Sample snippet
using NodaTime;
using System;
// Yes, in 1900 Paris did (according to TZDB) have a UTC offset of 9 minutes, 21 seconds.
DateTimeZone paris = DateTimeZoneProviders.Tzdb["Europe/Paris"];
Offset offset = paris.GetUtcOffset(Instant.FromUtc(1900, 1, 1, 0, 0));
Console.WriteLine(offset.ToString());
Output:
+00:09:21
GetZoneInterval(Instant)
Gets the zone interval for the given instant; the range of time around the instant in which the same Offset
applies (with the same split between standard time and daylight saving time, and with the same offset).
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public abstract ZoneInterval GetZoneInterval(Instant instant)
Parameters
Returns
Sample snippet
using NodaTime;
using NodaTime.TimeZones;
using System;
DateTimeZone london = DateTimeZoneProviders.Tzdb["Europe/London"];
ZoneInterval interval = london.GetZoneInterval(Instant.FromUtc(2010, 6, 19, 0, 0));
Console.WriteLine(interval.Name);
Console.WriteLine(interval.Start);
Console.WriteLine(interval.End);
Console.WriteLine(interval.WallOffset);
Console.WriteLine(interval.Savings);
Output:
BST
2010-03-28T01:00:00Z
2010-10-31T01:00:00Z
+01
+01
See Also
GetZoneIntervals(Instant, Instant)
Returns all the zone intervals which occur for any instant in the interval [start
, end
).
Since 1.1.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public IEnumerable<ZoneInterval> GetZoneIntervals(Instant start, Instant end)
Parameters
Type |
Name |
Description |
Instant |
start |
Inclusive start point of the interval for which to retrieve zone intervals. |
Instant |
end |
Exclusive end point of the interval for which to retrieve zone intervals. |
Returns
Type |
Description |
IEnumerable<ZoneInterval> |
A sequence of zone intervals covering the given interval. (The value returned is never null.) |
Exceptions
Type |
Condition |
ArgumentOutOfRangeException |
end is earlier than start . |
See Also
GetZoneIntervals(Interval)
Returns all the zone intervals which occur for any instant in the given interval.
Since 1.1.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public IEnumerable<ZoneInterval> GetZoneIntervals(Interval interval)
Parameters
Type |
Name |
Description |
Interval |
interval |
Interval to find zone intervals for. This is allowed to be unbounded (i.e.
infinite in both directions). |
Returns
Type |
Description |
IEnumerable<ZoneInterval> |
A sequence of zone intervals covering the given interval. (The value returned is never null.) |
See Also
GetZoneIntervals(Interval, ZoneEqualityComparer.Options)
Returns the zone intervals within the given interval, potentially coalescing some of the
original intervals according to options.
Since 2.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public IEnumerable<ZoneInterval> GetZoneIntervals(Interval interval, ZoneEqualityComparer.Options options)
Parameters
Type |
Name |
Description |
Interval |
interval |
Interval to find zone intervals for. This is allowed to be unbounded (i.e.
infinite in both directions). |
ZoneEqualityComparer.Options |
options |
|
Returns
Type |
Description |
IEnumerable<ZoneInterval> |
(The value returned is never null.) |
MapLocal(LocalDateTime)
Returns complete information about how the given
LocalDateTime is mapped in this time zone.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public virtual ZoneLocalMapping MapLocal(LocalDateTime localDateTime)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
The local date and time to map in this time zone. |
Returns
Type |
Description |
ZoneLocalMapping |
A mapping of the given local date and time to zero, one or two zoned date/time values. (The value returned is never null.) |
ResolveLocal(LocalDateTime, ZoneLocalMappingResolver)
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public ZonedDateTime ResolveLocal(LocalDateTime localDateTime, ZoneLocalMappingResolver resolver)
Parameters
Returns
Type |
Description |
ZonedDateTime |
The result of resolving the mapping. |
Exceptions
Type |
Condition |
ArgumentNullException |
resolver is null. |
ToString()
Returns the ID of this time zone.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public override string ToString()
Returns
Type |
Description |
String |
The ID of this time zone.
|
Overrides
System.Object.ToString()