从数据库返回的DateTime正常。但是在剃须刀中(在数据表中)显示为12:00:00。 enter image description here
负责从db获取记录的方法是可行的,因为它从数据库映射了正确的时间
public async Task<ActionResult> GetExtendedFanDetails(int FanId, int? ProfileId)
{
var profileFan = _fanService.GetFanProfileById(FanId, ProfileId);
var fanActivities = profileFan.Activities;
var deliveryActions = profileFan.DeliveryActions;
var model = new FansTableExtensionViewModel
{
FanId = (ProfileId.HasValue) ? profileFan.Id : FanId
};
if (fanActivities.Any())
{
foreach (var fanactivity in fanActivities)
{
model.FanActivities.Add(new FanActivitiesViewModel
{
Id = fanactivity.Id,
ActivityDate = fanactivity.Created.Date.ToString("dd/MM/yyyy HH:mm:ss"),
ActivityName = fanactivity.Activity.Name,
ActivityScore = fanactivity.Activity.Score,
ActivityType = "FAN Activity",
Message = fanactivity.Message
});
};
}
剃刀视图部分
<tbody>
@foreach (var item in Model.FanActivities)
{
<tr data-id="@item.Id">
<td>@item.ActivityName</td>
<td>@item.ActivityType</td>
<td>item.ActivityDate</td>
<td>@item.ActivityScore</td>
<td data-message="@item.Message">
@item.Message
</td>
</tr>
}
</tbody>
出什么问题了?我尝试了所有不同的组合
答案 0 :(得分:1)
DateTime
对象的Date
属性始终返回日期为12:00:00
。如果需要准确的时间,请直接使用DateTime
对象。
ActivityDate = fanactivity.Created.ToString("dd/MM/yyyy HH:mm:ss")