简体   繁体   English

Blazor 在页面加载时初始化日期

[英]Blazor initialize a date on page load

<div class="wrap-input100 validate-input">
    <span class="label-input100">Date of Birth</span>
    <InputDate class="input100" id="birthday" name="birthday" @bind-Value="CurrentCustomerSubmission.DateOfBirth" max="@DateTime(DateTime.Now.Year-60,1,1).ToString()" />
    <ValidationMessage For="@(() => CurrentCustomerSubmission.DateOfBirth)" />
</div>

What I am trying to do is have the initial value of the date to be我想要做的是将日期的初始值设为

1/1/(current year - 60) 1/1/(当年 - 60)

I can't seem to figure this out.我似乎无法弄清楚这一点。

I prefer DateTimeOffset over DateTime but the idea is still the same:我更喜欢 DateTimeOffset 而不是 DateTime,但想法仍然相同:

override protected void OnInitialized() // Where ever you are initialising your CurrentCustomer Submission
{
    CurrentCustomerSubmission = new Customer();
    CurrentCustomerSubmission.DateOfBirth =  new DateTime(DateTime.Now.Year - 60, 1, 1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM