BlazorLocalTime 1.0.4
See the version list below for details.
dotnet add package BlazorLocalTime --version 1.0.4
NuGet\Install-Package BlazorLocalTime -Version 1.0.4
<PackageReference Include="BlazorLocalTime" Version="1.0.4" />
<PackageVersion Include="BlazorLocalTime" Version="1.0.4" />
<PackageReference Include="BlazorLocalTime" />
paket add BlazorLocalTime --version 1.0.4
#r "nuget: BlazorLocalTime, 1.0.4"
#:package BlazorLocalTime@1.0.4
#addin nuget:?package=BlazorLocalTime&version=1.0.4
#tool nuget:?package=BlazorLocalTime&version=1.0.4
BlazorLocalTime
BlazorLocalTime provides functionality to convert DateTime values to the user's local time zone in Blazor applications.
Demo
arika0093.github.io/BlazorLocalTime/
Installation
Install BlazorLocalTime from NuGet:
dotnet add package BlazorLocalTime
Next, register the service in your Program.cs:
builder.Services.AddBlazorLocalTimeService();
Finally, add the following component to Routes.razor (or MainLayout.razor, etc.):
@using BlazorLocalTime
<BlazorLocalTimeProvider />
Using as a Component
To simply display a local time as text, use the LocalTimeText component:
<LocalTimeText Value="@DateTime.UtcNow" Format="yyyy-MM-dd HH:mm:ss" />
Alternatively, you can use the LocalTime component to receive the converted value in the child content:
<LocalTime Value="@DateTime.UtcNow" Context="dt">
@dt.ToString("yyyy-MM-dd HH:mm:ss")
</LocalTime>
If you want to use TimeZoneInfo, you can use the LocalTimeZone component:
<LocalTimeZone Context="tz">
<p>Current Time Zone: @tz.DisplayName</p>
</LocalTimeZone>
For input forms, it is common to display values in local time and save them as UTC.
You can easily create such forms using the LocalTimeForm component:
<LocalTimeForm @bind-Value="Dt" Context="dtf">
<InputDate Type="InputDateType.DateTimeLocal" @bind-Value="dtf.Value" />
</LocalTimeForm>
@code {
private DateTime Dt { get; set; } = DateTime.UtcNow;
}
Input forms also support separate date and time inputs:
<LocalTimeForm @bind-Value="Dt" Context="dtf">
<InputDate Type="InputDateType.Date" @bind-Value="dtf.Date" />
<InputDate Type="InputDateType.Time" @bind-Value="dtf.Time" />
</LocalTimeForm>
@code {
private DateTime Dt { get; set; } = DateTime.UtcNow;
}
Using with UI Libraries
The LocalTimeForm component can be used with various UI libraries to create forms that handle local time input.
Below are examples using MudBlazor, Fluent UI, and Ant Design Blazor components.
MudBlazor
<LocalTimeForm @bind-Value="Dt" Context="dtf">
<MudDatePicker Label="Date" @bind-Date="dtf.Value" ShowToolbar="false" />
<MudTimePicker Label="Time" @bind-Time="dtf.TimeSpan" ShowToolbar="false" />
</LocalTimeForm>
@code {
private DateTime? Dt { get; set; } = DateTime.UtcNow;
}
Fluent UI
<LocalTimeForm @bind-Value="Dt" Context="dtf">
<FluentDatePicker Label="Date" @bind-Value="dtf.Value" />
<FluentTimePicker Label="Time" @bind-Value="dtf.Value" />
</LocalTimeForm>
@code {
private DateTime? Dt { get; set; } = DateTime.UtcNow;
}
Ant Design Blazor
<LocalTimeForm @bind-Value="Dt" Context="dtf">
<DatePicker TValue="DateTime?" @bind-Value="dtf.Value" ShowTime="@true" />
@* Alternatively, you can use separate date and time pickers *@
<DatePicker TValue="DateOnly?" @bind-Value="dtf.Date" />
<TimePicker TValue="TimeOnly?" @bind-Value="dtf.Time" />
</LocalTimeForm>
@code {
private DateTime? Dt { get; set; } = DateTime.UtcNow;
}
Using as a Service
You can also use ILocalTimeService to convert values in your code:
@inject ILocalTimeService LocalTimeService
@code {
private void ButtonClicked()
{
var localNow = LocalTimeService.ToLocalTime(DateTime.UtcNow);
// or shorthand
// var localNow = LocalTimeService.Now;
}
}
During the initial rendering (OnInitialized), the user's local time zone may not be available yet, so conversion can fail.
In such cases, you can use ILocalTimeService.LocalTimeZoneChanged to wait until the local time zone becomes available.
@implements IDisposable
@inject ILocalTimeService LocalTimeService
@code {
protected override void OnInitialized()
{
LocalTimeService.LocalTimeZoneChanged += OnLocalTimeZoneChanged;
}
public void Dispose()
{
LocalTimeService.LocalTimeZoneChanged -= OnLocalTimeZoneChanged;
}
private void OnLocalTimeZoneChanged(object? sender, EventArgs e)
{
if(LocalTimeService.IsTimeZoneInfoAvailable)
{
// can use LocalTimeService.ToLocalTime() now
}
}
}
Reference
This article was used as a major reference. I would like to express my gratitude for the reference article.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.36)
- Microsoft.Bcl.TimeProvider (>= 9.0.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
-
net7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.20)
- Microsoft.Bcl.TimeProvider (>= 9.0.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.17)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 3,642 | 8/3/2026 |
| 2.0.3 | 14,647 | 11/18/2025 |
| 2.0.2 | 441 | 11/17/2025 |
| 2.0.1 | 348 | 11/12/2025 |
| 2.0.0-rc.0 | 128 | 10/3/2025 |
| 1.4.0 | 9,262 | 9/6/2025 |
| 1.3.0 | 574 | 7/2/2025 |
| 1.2.0 | 247 | 6/30/2025 |
| 1.1.2 | 216 | 6/26/2025 |
| 1.1.1 | 216 | 6/25/2025 |
| 1.1.0 | 213 | 6/25/2025 |
| 1.0.5 | 219 | 6/22/2025 |
| 1.0.4 | 219 | 6/22/2025 |
| 1.0.3 | 171 | 6/22/2025 |
| 1.0.2 | 163 | 6/21/2025 |
| 1.0.1 | 150 | 6/21/2025 |
| 0.2.1 | 171 | 6/20/2025 |
| 0.1.1 | 181 | 6/20/2025 |