如何删除日期的时间部分在C#中只DateTime对象? [英] How to remove time portion of date in C# in DateTime object only?

查看:519
本文介绍了如何删除日期的时间部分在C#中只DateTime对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除的日期时间时部分或可能具有的日期不是在字符串的形式对象表格格式如下code>。

I need to remove time portion of date time or probably have the date in following format in object form not in the form of string.

06/26/2009 00:00:00:000

因为我需要在日期我不能使用任何字符串转换方法对象的形式。

我第一次尝试转换的DateTime 字符串,从中取出时的具体日期,但它增加了 12:00:00 AM 当我将其转换回的DateTime 对象回来了。

I tried first converting the DateTime to a string, remove the time specific date from it, but it adds 12:00:00 AM as soon as I convert it back to DateTime object back again.

请帮忙。

推荐答案

使用日期属性:

var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;

日期变量将包含日期,时间部分将是 00:00:00

The date variable will contain the date, the time part will be 00:00:00.

这篇关于如何删除日期的时间部分在C#中只DateTime对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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