Beispiel #1
0
        /// <summary>
        /// Set "TimeZoneInfo.Local" to actual local time zone. (include "UseSystemTimeZones()")
        /// </summary>
        public static void UseLocalTimeZone(this IComponentsApplicationBuilder app)
        {
            app.UseSystemTimeZones();
            var jsRuntime = app.Services.GetService(typeof(IJSRuntime)) as IJSInProcessRuntime;

            if (jsRuntime != null)
            {
                var ianaTimeZoneName = jsRuntime.Invoke <string>("eval", "(function(){try { return ''+ Intl.DateTimeFormat().resolvedOptions().timeZone; } catch(e) {} return 'UTC';}())");
                TimeZoneKit.TimeZoneKit.SetLocalTimeZoneByIANAName(ianaTimeZoneName);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Set "TimeZoneInfo.Local" to the time zone that specified IANA name. (include "UseSystemTimeZones()")
 /// </summary>
 public static void UseLocalTimeZoneByIANAName(this IComponentsApplicationBuilder app, string ianaTimeZoneName)
 {
     app.UseSystemTimeZones();
     TimeZoneKit.TimeZoneKit.SetLocalTimeZoneByIANAName(ianaTimeZoneName);
 }
Beispiel #3
0
 /// <summary>
 /// Set "TimeZoneInfo.Local" to the time zone that specified id. (include "UseSystemTimeZones()")
 /// </summary>
 public static void UseLocalTimeZone(this IComponentsApplicationBuilder app, string timeZoneId)
 {
     app.UseSystemTimeZones();
     TimeZoneKit.TimeZoneKit.SetLocalTimeZone(timeZoneId);
 }