Giter VIP home page Giter VIP logo

timezoneconverter's Introduction

TimeZoneConverter NuGet Version

Lightweight library to convert quickly between IANA, Windows, and Rails time zone names.

Installation

PM> Install-Package TimeZoneConverter

This library should be compatible with .NET Standard 1.1 and greater, as well as .NET Framework 3.5 and greater. See the .NET Standard Platform Support Matrix for further details about .NET Standard, and please raise an issue if you encounter any compatibility errors.

Notes

This library uses a combination of data sources to achieve its goals:

Usually, the latter is reserved for edge cases, and for newly-introduced zones that may or may not have been published to official sources yet.

Important: Since this data can change whenever new time zones are introduced from any of these sources, it is recommended that you always use the most current revision, and check for updates regularly.

Additionally, this library does not attempt to determine if the time zone IDs provided are actually present on the computer where the code is running. It is assumed that the computer is kept current with time zone updates.

For example, if one attempts to convert Africa/Khartoum to a Windows time zone ID, they will get Sudan Standard Time. If it is then used on a Windows computer that does not yet have KB4051956 installed (which created this time zone), they will likely get a TimeZoneNotFoundException.

Example Usage

Convert an IANA time zone name to the best fitting Windows time zone ID.

string tz = TZConvert.IanaToWindows("America/New_York");
// Result:  "Eastern Standard Time"

Convert a Windows time zone name to the best fitting IANA time zone name.

string tz = TZConvert.WindowsToIana("Eastern Standard Time");
// result:  "America/New_York"

Convert a Windows time zone name to the best fitting IANA time zone name, with regard to a specific country.

string tz = TZConvert.WindowsToIana("Eastern Standard Time", "CA");
// result:  "America/Toronto"

Get a TimeZoneInfo object from .NET Core, regardless of what OS you are running on:
Helps with .NET CoreFX issue #11897
This function is only available for .NET Standard 1.3+ or full .NET Framework targets

// Either of these will work on any platform:
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("Eastern Standard Time");
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("America/New_York");

Convert a Rails time zone name to the best fitting IANA time zone name.

string tz = TZConvert.RailsToIana("Mexico City");
// result:  "America/Mexico_City"

Convert a Rails time zone name to the best fitting Windows time zone ID.

string tz = TZConvert.RailsToWindows("Mexico City");
// result:  "Central Standard Time (Mexico)"

Convert an IANA time zone name to one or more Rails time zone names.

IList<string> tz = TZConvert.IanaToRails("America/Mexico_City");
// Result:  { "Guadalajara", "Mexico City" }

Convert a Windows time zone ID to one or more Rails time zone names.

IList<string> tz = TZConvert.WindowsToRails("Central Standard Time (Mexico)");
// Result:  { "Guadalajara", "Mexico City" }

License

This library is provided free of charge, under the terms of the MIT license.

timezoneconverter's People

Contributors

mattjohnsonpint avatar fernandolguevara avatar

Watchers

WeiPlanet avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.