如何获得在asp.net C#中只排除了日期和时间 [英] How to get only the date excluding time in asp.net c#

查看:153
本文介绍了如何获得在asp.net C#中只排除了日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得唯一不包括asp.net C#中的时间日期。我想被作为输入唯一的日期查找例如像2013年3月11日


解决方案

您可以使用的 DateTime.Date 获得DateTime对象的唯一日期部分

 的DateTime dateOnly = date1.Date;

具有相同的日期作为该实例的新对象,并设置为 12:00:00 的午夜( 00:00:00 的)。

如果您在字符串中的日期,并希望将其转换为DateTime对象首先那么你可以使用的 DateTime.ParseExact

 结果= DateTime.ParseExact(2013年3月11日,D / MM / YYYY,CultureInfo.InvariantCulture);

How to get only the date excluding time in asp.net c#. I want only the date to be given as input to search like eg 3/11/2013

解决方案

You can use DateTime.Date to get only date part of DateTime object

DateTime dateOnly = date1.Date;

A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).

If you have the Date in string and want to convert it to DateTime object first then you can use DateTime.ParseExact

result = DateTime.ParseExact("3/11/2013", "d/MM/yyyy", CultureInfo.InvariantCulture);

这篇关于如何获得在asp.net C#中只排除了日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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