没有时间使用DateTime.Today的日期 [英] Date without time using DateTime.Today

查看:214
本文介绍了没有时间使用DateTime.Today的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这段代码Obj.TransDate = DateTime.Today;

它的工作但它的传递日期和时间两者但我只想要指定格式的DATE。

解决方案

 Obj.TransDate = DateTime.Today.Date; 





请参阅 DateTime.Date Property [ ^ ]



注意: .Date 属性返回日期时间为00:00:00。这是返回没有时间组件的日期的方式。使用带有DateTime数据类型的 .Date 属性来仅访问DateTime数据类型的日期部分。


您需要转换它...



 DateTime date1 = DateTime.Today; 
DateTime dateOnly = date1.Date;
MessageBox.Show(dateOnly.ToString( d));


你好,

如果你使用的是c#,那么下面的代码肯定会解决你的问题::

< pre lang =vb> string date = string .Empty;
date = DateTime.Now.ToString();
date = date .Split(' ')[0];
MessageBox.Show( date );





-Abhishek Chopra


I write this code "Obj.TransDate = DateTime.Today;"
its working but its pass date and time both but i want only DATE in specified format.

解决方案

Obj.TransDate = DateTime.Today.Date;



See documentation at DateTime.Date Property[^]

Note: The .Date property returns the date with a time of 00:00:00. This is how dates without a time component are returned. Use the .Date property with a DateTime Data Type to access only the date part of the DateTime Data Type.


You need to convert it ...

DateTime date1 = DateTime.Today;
DateTime dateOnly = date1.Date;
MessageBox.Show(dateOnly.ToString("d"));


Hello,
If you are using c#, then following code will solve your problem for sure::

string date = string.Empty;
date = DateTime.Now.ToString();
date = date.Split(' ')[0];
MessageBox.Show(date);



-Abhishek Chopra


这篇关于没有时间使用DateTime.Today的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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