ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
DateTimePicker how to set custom datetime format yyyy-MM-dd HH:mm:ss
Title:
B
I
{code}
?
@Html.Awe().DateTimePicker(new DateTimePickerOpt { Name = "txt起始日期時間", ClearBtn = true, ShowSeconds=true, CssClass= "DateTimeInput", Placeholder = "StartDate..." }) datatime show 2025/7/9 上午 09:42:57 How set to show 2025-07-09 09:42:57
Save Changes
Cancel
RayBen
asked 3 days ago
Answers
B
I
{code}
?
The datetime format used by the datepicker is based on the current thread culture (user browser), if you change that it will also change the format, for example in our demo when you change the language from the dropdown in the top right corner the date format also changes. You could hardcode one culture for all users if you want one dateformat to be used by everyone; in Program.cs: var app = builder.Build(); // Set default thread culture globally var myCulture = new CultureInfo("en-US"); CultureInfo.DefaultThreadCurrentCulture = myCulture; CultureInfo.DefaultThreadCurrentUICulture = myCulture; as an alternative you can set the `Format`, example `@Html.Awe().DateTimePicker(new DateTimePickerOpt { Format = "..."` but if you do that note that the ModelBinder will still use the current thread culture to parse strings to dates, so you could use a string type for the date field and parse the string to date manually
Save Changes
Cancel
Omu
answered 3 days ago
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK