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 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...
随机推荐
- WePY | 小程序组件化开发框架
资源连接: WePY | 小程序组件化开发框架 WePYAWESOME 微信小程序wepy开发资源汇总 文档 GITHUB weui WebStorm/PhpStorm 配置识别 *.wpy 文件代码 ...
- SQL循环语句 详解
SQL循环语句 declare @i int set @i=1 while @i<30 begin insert into test (userid) values(@i) set @i=@i+ ...
- ⌈洛谷1505⌋⌈BZOJ2157⌋⌈国家集训队⌋旅游【树链剖分】
题目链接 [洛谷] [BZOJ] 题目描述 Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T ...
- 每天一个linux命令(1):wc命令
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...
- HDU46093-idiots
题目大意 给一堆边的长度,问从中随机选出三条边来能够组成三角形的概率. 题解 其实就是要求能够组成三角形的方案数.直接从三条边入手问题会很复杂,所以我们可以先求出f[x]表示随便选出两条边长度之和为x ...
- [BJOI2012]最多的方案(记忆化搜索)
第二关和很出名的斐波那契数列有关,地球上的OIer都知道:F1=1, F2=2, Fi = Fi-1 + Fi-2,每一项都可以称为斐波那契数.现在给一个正整数N,它可以写成一些斐波那契数的和的形式. ...
- 编写高质量代码:改善Java程序的151个建议 --[36~51]
编写高质量代码:改善Java程序的151个建议 --[36~51] 工具类不可实例化 工具类的方法和属性都是静态的,不需要生成实例即可访 问,而且JDK也做了很好的处理,由于不希望被初始化,于是就设置 ...
- A1043. Is It a Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- redis五种数据类型的使用场景
string 1.String 常用命令: 除了get.set.incr.decr mget等操作外,Redis还提供了下面一些操作: 获取字符串长度 往字符串append内容 设置和获取字符串的某一 ...
- 计算机基础:计算机网络-chapter6应用层
应用层为协议最顶部,为用户服务. 常见的服务:邮件,万维网,DNS等 DNS:使用UDP承载,部分使用TCP协议 作用 将域名映射为IP 域名格式:自己到上级域名的访问 DNS服务器提供域名的资源记录 ...