xtrareports-devexpress-dot-xtrareports-dot-services-d95d0f1f.md
Provides information about the local time zone in the UtcToLocalTime and LocalToUtcTime expression functions.
Namespace : DevExpress.XtraReports.Services
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public interface ITimeZoneProvider
Public Interface ITimeZoneProvider
You can use UtcToLocalTime and LocalToUtcTime functions to convert date-time values to local or UTC time zones. The local time zone is determined by the server’s settings. To provide a different time zone (for example, the client’s time zone), implement the ITimeZoneProvider interface. The GetCurrentTimeZone method should return a TimeZoneInfo object that is the local time zone.
The following example implements the ITimeZoneProvider interface in an ASP.NET Core application. In this example, the time zone is retrieved from a cookie named LocalTimeZone.
ITimeZoneProvider interface:using System;
using DevExpress.XtraReports.Services;
using Microsoft.AspNetCore.Http;
namespace AspNetCoreApp.Services {
public class CustomTimeZoneProvider : ITimeZoneProvider {
private readonly string timeZoneId;
public CustomTimeZoneProvider(IHttpContextAccessor httpContextAccessor) {
timeZoneId = httpContextAccessor.HttpContext?.Request.Cookies["LocalTimeZone"];
}
public TimeZoneInfo GetCurrentTimeZone() {
var tzId = timeZoneId ?? "UTC";
try {
return TimeZoneInfo.FindSystemTimeZoneById(tzId);
} catch {
return TimeZoneInfo.Utc;
}
}
}
}
In the Program.cs file, register the CustomTimeZoneProvider service:
In the view, set the LocalTimeZone cookie to the client’s time zone:
In desktop applications, register the ITimeZoneProvider implementation at the XtraReport instance level.
See Also
Convert Time Zones (ASP.NET Core)
Convert Time Zones (ASP.NET MVC)