Changing Moment.js C # .NET point in time

Is there a C # plugin available that handles all time.js timezones.

I'm having a hard time comparing dates in the backend since the timezones from moment.js don't match the timezones from .net DateTime.

I need to convert times to Utc before comparing different dates to dates. I am using nodatime and it is capable of handling some of the time zones, but not all.


EDIT: NodaTime handled most timezones, but I still need to cover the abbreviations. Is there something for this?



source to share

1 answer

So NodaTime handled Olson's time zones as well as GMT +, UTC and others. For acronyms I solved with this

public static DateTimeZone GetTimeZone(string id)
        DateTimeZone timezone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(id);

        if (timezone == null) {
            var instant = Instant.FromDateTimeUtc(DateTime.UtcNow);
            var source = DateTimeZoneProviders.Tzdb;
            id = source.Ids.Where(i => source[i].GetZoneInterval(instant).Name == id).FirstOrDefault();
            timezone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(id);

        return timezone;




All Articles