Nullable<DateTime> DateTime? 格式转换问题 tostring()
解决方案:
DateTime? dt2 = DateTime.Now;
dt2.GetValueOrDefault().ToString("yyyy-MM-dd");
控制器代码:
public ViewResult index()
{
var db = new db_context();
var model = db.test;
return View(model);
}
views代码:
<table border="1" cellpadding="6" cellspacing="0" bordercolor="#CCC" style="border-collapse:collapse;">
<tr>
<th>
@Html.DisplayNameFor(model => model.test_title)
</th>
<th>
@Html.DisplayNameFor(model => model.create_time)
</th>
<th>
@Html.DisplayNameFor(model => model.update_time)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.test_title)
</td>
<td>
@Html.DisplayFor(modelItem => item.create_time)
</td>
<td>
@item.update_time.GetValueOrDefault().ToString("yyyy-MM-dd HH:mm")
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.id }) |
@Html.ActionLink("Details", "Details", new { id = item.id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.id })
</td>
</tr>
}
</table>
页面效果:

Nullable<DateTime> DateTime? 格式转换问题 tostring()的更多相关文章
- C# MVC 用户登录状态判断 【C#】list 去重(转载) js 日期格式转换(转载) C#日期转换(转载) Nullable<System.DateTime>日期格式转换 (转载) Asp.Net MVC中Action跳转(转载)
C# MVC 用户登录状态判断 来源:https://www.cnblogs.com/cherryzhou/p/4978342.html 在Filters文件夹下添加一个类Authenticati ...
- Nullable<System.DateTime>日期格式转换 (转载)
一.问题 1.html页面中时间显示出错,数据库中时间是正确的. 原因:没有把DateTime转成String类型. 2. 在C#中,发现不能直接使用ToString("yyyy-MM-d ...
- datetime.strptime格式转换报错ValueError
今天遇到一个报错:ValueError: time data '2018-10-10(Wednesday) AM0:50' does not match format '%Y-%m-%d(%A) %p ...
- DateTime日期格式转换,不受系统格式的影响
Application.Initialize; with FormatSettings do begin ShortDateFormat := 'yyyy-mm-dd'; LongDa ...
- DateTime格式转换部分介绍
DateTime与字符串转换: DateTime()与转换为字符串主要依靠DateTime().ToString(string format) 函数,以我的理解,参数format大体分为单个字母和多个 ...
- C# DATETIME格式转换汇总 根据日期获取星期
原文:C# DATETIME格式转换汇总 根据日期获取星期 C# DateTime.Now.Year --2019(年) DateTime.Now.Month --9(月) DateTime.Now. ...
- 带毫秒的字符转换成时间(DateTime)格式的通用方法
C#自身有更好的方式,Net任意String格式转换为DateTime类型 ====================================================== 原文 ==== ...
- Json 的日期格式转换成DateTime
JSON 的日期形式:”/Date(1242357713797+0800)/” , 下面我们就用以下C#的方法将他转换成DateTime类型: /// <summary> /// Json ...
- python中将HTTP头部中的GMT时间转换成datetime时间格式
原文: https://blog.csdn.net/zoulonglong/article/details/80585716 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...
随机推荐
- 微信开发使用webstorm&phpstrom 配置
材料: 下载链接:https://pan.baidu.com/s/1pLn6jFl 密码:fgo5 -----(将其中的wecharCode.jar 下载下来,然后在webStorm 的 File ...
- 【HDU - 4348】To the moon(主席树在线区间更新)
BUPT2017 wintertraining(15) #8G 题意 给一个数组a,有n个数,m次操作.\(N, M ≤ 10^5, |A i| ≤ 10^9, 1 ≤ l ≤ r ≤ N, |d| ...
- VSCode设置Tab键为4个空格
升级之后莫名蛋疼,Tab键变成了8个,每次缩进之后都要格式化一下,比较麻烦,所以来一篇设置: GIF演示整个过程 分步骤走: 设置一下 设置为4个空格 最后多一句嘴,Python3开始官方不建议使用制 ...
- CSS解决文字超出显示省略号问题
超出一行 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 超出多行 overflow: hidden; text-ove ...
- vetur插件提示 'v-for' directives require 'v-bind:key' directives.错误的解决办法
在用vscode编写vue代码时,因为安装的有vetur插件,所以当代码中有v-for语法时,会提示 [vue-language-server] 'v-for' directives require ...
- django(六)之ORM数据库操作
https://www.cnblogs.com/haiyan123/p/7732190.html 一.ORM介绍 ORM——object relation mapping 映射关系: 表名 ----- ...
- Spring2
简介:1.Aop编程.2.AspectJ基于xml文件.3.AspectJ基于注解. 4.JdbcTemplate. 5.配置properties文件 1 AOP 1.1 AOP介绍 ...
- Ubuntu系统修改BIOS时间问题
http://forum.ubuntu.org.cn/viewtopic.php?t=477606 ubuntu16.04将硬件时间改为CST 原因: 在安装ubuntu双系统的情况下,ubuntu的 ...
- django系列 1 :python+django环境搭建 +mac提示找不到manage.py命令
1.安装python3 2.设置python3的环境变量 3.进入命令行模式,输入 pip install django 1.10.3 4.验证是否安装完成 pip show django 5.dja ...
- maven+testng+eclipse
1.安装maven 2.安装testng 3.配置maven的dependency,和build <project xmlns="http://maven.apache.org/POM ...