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 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...
随机推荐
- EtherType :以太网类型字段及值
Ethernet II即DIX 2.0:Xerox与DEC.Intel在1982年制定的以太网标准帧格式.Cisco名称为:ARPA Ethernet II类型以太网帧的最小长度为64字节(6+6+2 ...
- 「FJOI2016」神秘数 解题报告
「FJOI2016」神秘数 这题不sb,我挺sb的... 我连不带区间的都不会哇 考虑给你一个整数集,如何求这个神秘数 这有点像一个01背包,复杂度和值域有关.但是你发现01背包可以求出更多的东西,就 ...
- Ability
Base:网络安全,sklearn(ML),日本語,企业存储 Branch1:自动化,Git Branch2:HW系统架构 Branch3:shadowsocks源码:
- 2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat
题意:四个操作,区间加,区间每个数乘,区间的数变成 2^64-1-x,求区间和. 题解:2^64-1-x=(2^64-1)-x 因为模数为2^64,-x%2^64=-1*x%2^64 由负数取模的性质 ...
- Shiro中的Remember me设置
1. 在Spring的相关配置文件中加入如下Remember me管理器配置: <!-- rememberMe管理器 --> <bean id="rememberMeMan ...
- webpack入门(一)webpack的动机 ---前端专业英语
记得某次考试,出国N年老师出的卷子全是英语,坑的英语不好的我们不要不要的.幸亏上了专业英语课.最重要的是专业英语对于我们很重要,比如webpack,一堆博客都是几小时入门,如何会用webpack,当你 ...
- codeblocks: 使用动态链接库(pcre)的配置
说明:在c/c++程序中使用动态链接库, 编译后需要相关的dll文件(如:libpcre-1.dll,libpcreposix-0.dll)才能正常的运行. 2014-06-27
- python(字符串、列表、字典、元组、集合)的常用内置方法
一.字符串: lis='my name is maple' res=lis.count('m')#计算字符串内相同字符的个数 print(res) lis='my name is maple' res ...
- unittest的使用三——断言
常用的断言有3种: 判断两个值是不是都相等,参数分别是第一个值,第二个值,msg代表不想等的话,描述的信息 def assertEqual(self, first, second, msg=None) ...
- Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)
E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...