admin管理员组文章数量:1315375
I am having trouble showing the date in the correct format. On one site I enter the date with the function:
<td><input type="date" class="form-control"/> </td>
As far as I understand, type date uses the browser date format.
On a table overview site I want to show the before entered date in the same format (I would go with the browser format as well). I tried so far:
@using System.Globalization
<td>@a.EnabledUntil.Value.ToString("d", CultureInfo.CurrentUICulture)</td>
or:
<td>@a.EnabledUntil.Value.ToString("d", CultureInfo.CurrentCulture)</td>
My problem is, on the input the format is dd/MM/yyyy
, but on the overview it is MM/dd/yyyy
.
On the model it has the type DateTime and is stored in a SQLite DB.
I don't want to hard code the date format, but how can I align both in the same format?
Thanks
Stephan
Edit: I used finally the ChatGpt solution with javascript:
<td class="date-cell" data-date="@a.EnabledUntil?.ToString("yyyy-MM-dd")"></td>
and JavaScript:
<script>
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".date-cell").forEach(td => {
const rawDate = td.getAttribute("data-date");
if (rawDate) {
td.textContent = new Date(rawDate).toLocaleDateString(); // Uses the browser’s locale format
}
});
});
</script>
I am just not sure if this is a good way, but it works when I switch browsers language
本文标签: aspnetSame date format for 39input typequotdatequot39 and display in tableStack Overflow
版权声明:本文标题:asp.net - Same date format for 'input type="date"' and display in table - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741974992a2408065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论