public DateTimeOffset CreateAt { get; set; }
public timeFormat()
{
this.CreateAt = DateTime.Now;
}
结果:2020年4月29日上午10:18:43 +07:00
如何在 View 页面中将 CreateAt 中的日期时间格式设置为 (4/29/20 10:18 AM)?
最佳答案
在您看来,您可以根据需要设置日期时间字符串的格式
例如这段代码
@Model.CreatedAt.ToString("dd-MM-yyyy HH:mm tt")
将输出:29-04-2020 10:18 AM
请参阅文档了解所有格式选项:https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
关于c# - 如何在模型中设置格式DateTimeOffset?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61516223/