获取短日期为系统可空日期时间(日期时间?)在C# [英] Get short date for System Nullable datetime (datetime ?) in C#

查看:211
本文介绍了获取短日期为系统可空日期时间(日期时间?)在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得短日期为获取短期日期系统可为空的日期时间(日期时间?)

How to get short date for Get short date for System Nullable datetime (datetime ?)

有关ED 12/31/2013 12:00:00 - >只应返回 12/31/2013

for ed 12/31/2013 12:00:00 --> only should return 12/31/2013.

我没有看到 ToShortDateString 可用。

推荐答案

您需要使用。价值第一(因为它是可为空)。

You need to use .Value first (Since it's nullable).

var shortString = yourDate.Value.ToShortDateString();

但也检查 yourDate 的值:

if (yourDate.HasValue) {
   var shortString = yourDate.Value.ToShortDateString();
}

这篇关于获取短日期为系统可空日期时间(日期时间?)在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆