如何从转换的日期时间中提取日期 [英] How to extract Date from converted datetime

查看:305
本文介绍了如何从转换的日期时间中提取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

DateTime FromDate = Convert.ToDateTime(dtFromDate.Value);



它返回{4/15/2015上午12:00:00}日期

但我只想要日期2015/4/15



我该怎么做

plz帮帮我...

my code is
DateTime FromDate = Convert.ToDateTime(dtFromDate.Value);

it return {4/15/2015 12:00:00 AM} date
but i want only Date "4/15/2015"

How can i do this
plz help me...

推荐答案

你不能 - 但没关系! :笑:



DateTime值就是:日期和时间 - 事实上,它在内部存储为自任意时间点以来的微秒数,因此它在物理上不能作为日期输出时间组件存在。



但这没关系,因为时间组件唯一重要的时间是您尝试通过将DateTime值格式化为字符串来向用户显示DateTime值。

默认转换包括当前Culture指定格式的完整日期和时间,但您可以选择所需的任何格式: 格式化日期时间以显示 - 格式字符串说明 [ ^ ]
You can't - but it doesn't matter! :laugh:

A DateTime value is just that: a Date and a Time - in fact, it's stored internally as a number of microseconds since an arbitrary point in time, so it physically can't exist as a date output a time component.

But it doesn't matter, because the only time that the Time component is significant is when you try to present the DateTime value to the user by formatting it into a string.
The default conversion includes the full date and time in the current Culture specified format, but you can select any formatting you want: Formatting a DateTime for display - format string description[^]


var date = FromDate.Date;





看看这个参考



Look at this reference

FromDate.ToString("d");


这篇关于如何从转换的日期时间中提取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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