Standarize the date across all your projects using this library. Library created for applications who needs to have a precise date and time on different timezones and locations.
Our profile on the NuGet library brokenegg.io
Use the package manager NuGet to install DotIni.
nuget install brokenegg.metadate
using System.IO;
using Brokenegg.MetaDate;
Setting global Time Zone as Manaus Time Zone (UTC-4)
USettings.Locale = ULocale.FindLocale(ELocales.MANAUS);
Converting date local to UTC (back and forth)
var date = DateTime.ParseExact("25/10/2021 20:25", "dd/MM/yyyy HH:mm", null);
var uDate = new UDate(date);
var local = uDate.ToLocalDateTime();
var utc = uDate.ToUtcDateTime();
local
should be the date 25/10/2021 20:25
utc
should be the date 26/10/2021 00:25
You can use different locales for each date you want, instead of using a global setting, as shown bellow:
var date = DateTime.ParseExact("25/10/2021 20:25", "dd/MM/yyyy HH:mm", null);
var uDate = new UDate(date, ELocales.MANAUS);
var local = uDate.ToLocalDateTime();
var utc = uDate.ToUtcDateTime();
local
should be the date 25/10/2021 20:25
utc
should be the date 26/10/2021 00:25
We have prepared the repo Brokenegg.MetaDate.Example which contains some usefull examples.
If you didn't find your timezone listed on the xml file at Brokenegg.MetaDate.timezones.xml
please open an issue or set up a pull request to the main branch and we will gladly integrate it. Remember to use _
to separate each word if your timezone has more than one word.
Example of how the timezones is structured:
<locales>
<locale>
<name>MANAUS</name>
<hours>-4</hours>
<minutes>0</minutes>
</locale>
<locales>
And add the enum for your Timezone on the enum Brokenegg.MetaDate.ELocales
:
public enum ELocales
{
MANAUS,
}
Please make sure to update tests as appropriate.