I have input tag(InputDate) in EditForm in Blazor file.
<div >
<label>Check In Date</label>
<InputDate @bind-Value="HomeModel.StartDate" min="@DateTime.Now.ToString("MM/dd/yyyy")" type="text"/>
</div>
then submit this to api server.
But problem is DateTime format with Url, it shows
https://localhost:44320/api/hotelroom?checkInDate=04. 12. 2022&checkOutDate=04. 13. 2022
So the return value is 400 error.
When I check this datetime format with swagger, nothing problem.
StartDate is checkInDate in Url.
when I try to debug, checkInDate shows like '04. 11. 2022'.
I expect this as 04/11/2022.
My pc is set for Japan. Without changing local pc's time setting, is there any way to fix this?
CodePudding user response:
Another possible solution it's changing the culture of the project when you run it, so in your startup class you should add:
app.UseRequestLocalization(options =>
{
var supportedCultures = new[] { "en-US" };
options.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures)
.SetDefaultCulture("en-US");
});
Using provider like
ToString("MM/dd/yyyy", new CultureInfo("en-US"))
Will force you to set every ToString with the new culture info (which can be tedious on a large scale)
CodePudding user response:
Even though I used 'ToString("MM/dd/yyyy")' method to trans parameter as string, the url always was like this
04. 12. 2022
So I used provider
ToString("MM/dd/yyyy", new CultureInfo("en-US"))
Then everything is good. string format can't surpass OS system setting.
Thank you all guys replied to my question.