且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET Core 2.0,RAZOR标记助手中设置日期,时间,数字的格式

更新时间:2023-12-05 22:10:10

我正在ASP.NET Core中工作,并且找到了解决该问题的方法,这个问题困扰了我一个星期(但并没有解决我的问题).我在这里或其他地方找到的任何论坛中都感到满意.)

I'm working in ASP.NET Core and have found a solution to this problem that puzzled me off and on for a week (and was not resolved to my satisfaction in any of the forums I found here or elsewhere.)

我不想在模型或控制器中编辑属性,因为我希望将整个日期(带有时间戳)存储在数据库中.

I did not want to edit the property in the model or in the controller because I wanted the whole date (with timestamp) to be stored in the database.

解决方案是在视图中传递@item.CreatedDate.Date.ToShortDateString(),现在在希望显示有限日期信息的页面上传递我想要的格式MM/DD/YYYY. ("CreatedDate"是我的财产).希望能消除一些头痛.

The solution was to pass @item.CreatedDate.Date.ToShortDateString() in the view, now my desired format MM/DD/YYYY on the page where I want limited date information displayed. ("CreatedDate" is my property). Hope that clears up some headaches.