I'm using ASP.NET Core MVC & jQuery Project
Below code works correctly, but i always need to use TimezoneHelper.ConvertFromUtc to convert utc date time from server to Client's set Timezone Date time. If i not convert it then it always shows utc date time as it is from server into datetimepicker.
Is There anything that datetimepicker convert this automatically and display client timezone's datetime without converting it in cshtml views?
I have set ClockProviders.Utc in Configure method of startup.cs file as below:
//Initializes ABP framework.
app.UseAbp(options =>
{
options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
Clock.Provider = ClockProviders.Utc; // Add the clock setting
});
App/Views/SalesEnquiry/ManageSalesEnquiry.cshtml file
@{
var currentTimezone = await SettingManager.GetSettingValueAsync(TimingSettingNames.TimeZone);
Model.SalesEnquiry.EnquiryDate = TimezoneHelper.ConvertFromUtc(Model.SalesEnquiry.EnquiryDate, currentTimezone).Value;
}
<label>@L("EnquiryDate")</label>@Html.TextBox("EnquiryDate", Model.SalesEnquiry.EnquiryDate, new { @class = "form-control m-input", required = "required", autocomplete = "off" })<span class="input-group-text"><span class="far fa-calendar-alt"></span></span><br>
/ManageSalesEnquiry.js file
$('#EnquiryDate').datetimepicker({
locale: abp.localization.currentLanguage.name,
format: 'L LT'
});
19 Answer(s)
-
0
Hi @ryan.mennell,
Can you check if this line https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/wwwroot/Common/Scripts/librarySettings.js#L5 is hit when you refresh the page when you put a
debuggerhere ?And also share value of
abp.timing.timeZoneInfo.iana.timeZoneIdif it is hit ?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thanks for the quick response. Apologies for the delay with mine.
Yes it is hitting and value of abp.timing.timeZoneInfo.iana.timeZoneId is "Europe/London"
Host timezone i set is Default [UTC]. Tenant timezone i set is GMT Standard Time.
Enquiry Date value in tenant database is 2020-05-25 08:00:00.0000000. which will be considered as UTC as i set ClockProviders.UTC.
However, On tenant login > enquiry page > DateTimePicker field > i get same date time "25/05/2020 08:00" if i do not convert it manually with "TimezoneHelper.ConvertFromUtc".
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Just bumping this fo visibility.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Apologies for bumping this again, I can clearly see there is high number of support tickets.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @ryan.mennell,
Sorry for the delay. Could you send your project via email to [email protected] ? We can fix this problem or offer you a better solution rather than using
TimezoneHelper.ConvertFromUtc.Thanks,
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I have sent the project via email. Could you get back to me asap.
Thanks Ryan
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hello,
I have recently purchased this and unable to fix this issue on my own.
I have sent the project via email with zero response (9 Days ago).
Could you please get back to me ASAP.
Kind Regards Ryan
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi Support Team, Any update on this? I am facing the same issue.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I'm also dealing with the exact same issue. I have the same setup as the original poster.
I never noticed it before as I had always asumed the functionality was working as documented. However in testing this week it was discovered that the date in the client view is not being converted from UTC. In fact when the user enters a date via an input or the datetimepicker, the new local datetime is exactly what is then stored in the database. So in short there is zero conversion going on for some reason.
The conversion/formatting works fine when displayed in datatables, but not in an input within a form.
I have also confirmed the line above is being hit and returning "America/Chicago" - is anyone working on a solution for this issue?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @atlscoob,
Do you use jQuery version or Angular version ?
Thanks,
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I'm using the jQuery version 6.8.0 is the last version we upgraded to I believe.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I am also using jQuery version.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Could you please update me on this issue? I have also sent emails with zero answers.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @ryan.mennell
You can add new function something like "ConvertToUserTimezone" to https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/Views/AbpZeroTemplateRazorPage.cs and use it. It will be accessable from all razor page
I also create an issue about that: https://github.com/aspnetzero/aspnet-zero-core/issues/3379 (radtool generated pages should handle it automatically)
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@derirmusa
Thank you, I will test this and let you know if I have any issues.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
What exactly is it we should be adding to that class? I'm not exactly clear as to what the function should be doing. Also once the function is added, when is it supposed to be called - from the controller when the view is generated?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @atlscoob,
You should create a method like this;
public async Task<DateTime> ConvertToUserTimezone(DateTime date ){ var currentTimezone = await SettingManager.GetSettingValueAsync(TimingSettingNames.TimeZone); rerturn TimezoneHelper.ConvertFromUtc(date, currentTimezone).Value; }and call it in your cshtml file like below;
<label>@L("EnquiryDate")</label>@Html.TextBox("EnquiryDate", ConvertToUserTimezone(Model.SalesEnquiry.EnquiryDate), new { @class = "form-control m-input", required = "required", autocomplete = "off" })<span class="input-group-text"><span class="far fa-calendar-alt"></span></span><br>Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
It means I have to do this on every view, ANZ is not handling this by default.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @Mazharmig,
Yes, correct. Sometimes you might want to show the DateTime without modifying it. So, this is the best way.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)