Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

DateRangePicker in mudblazor with UTC is behaving differently

$
0
0

I am working with mudblazor Daterangepicker. I wanted to make sure the date I selected will be saved as UTC not any other date kind. so I used ToUniversalTime() but instead of making it 24' hrs clock time .It takes 12 hrs clock time AM and PM. How to make sure My result is in UTC.

<MudDateRangePicker Label="Date Range Picker" PickerVariant="PickerVariant.Dialog" MinDate="DateTime.UtcNow.AddDays(-1)" MaxDate="@(uSB.DurationstartDate.HasValue ? uSB.DurationstartDate.Value.AddDays(4) : null)" For="@(() => uSB.DurationstartDate)" Variant="Variant.Outlined"  DateRangeChanged="@((args) =>{ uSB.DurationstartDate = args.Start.Value.ToUniversalTime(); // Enforce maximum of 5 days from start date if (args.End.HasValue && args.Start.HasValue) {     var maxEndDate = args.Start.Value.AddDays(4);     uSB.DurationendDate = args.End.Value > maxEndDate ? maxEndDate.ToUniversalTime() :         args.End.Value.ToUniversalTime(); } else {     uSB.DurationendDate =args.End.Value.ToUniversalTime().AddHours(23).AddMinutes(59); }})" DateRange="new DateRange(uSB.DurationstartDate, uSB.DurationendDate)" />

I want to make sure the datetime I store should be in UTCI also tried this method

    DateTime ForceToUtc(DateTime date){return date.Kind switch{    DateTimeKind.Utc => date,    DateTimeKind.Local => date.ToUniversalTime(),    DateTimeKind.Unspecified => DateTime.SpecifyKind(date, DateTimeKind.Local).ToUniversalTime(),    _ => date};}

I still get the output eg: '6/20/2025 12:00:00 AM' in this format.How to solve it.

Thank you!!!


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>