DateTime的日期 [英] Date from DateTime

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

问题描述

由于Convert.ToDateTime(),在SQL中选择时,日期类型会转换为DateTime,所以在DataGridView中显示日期时,我添加了.Date

 DataGridview.Rows [x] .Cells [" ColumnName"]。value = ListName [x] .GetDate()。date; 

但这显示时间00:00:00  为什么?


然后我尝试了

 var Date = ListName [x] .GetDate()。ToShortDateString(); 
DataGridView.Rows [x] .Cells [" ColumnName"]。value = Date;


 

这也显示时间00:00:00 

 var year = ListName [x] .GetDate()。Year; 
var month = ListName [x] .GetDate()。Month;
var day = ListName [x] .GetDate()。Day;
DataGridView.Rows [x] .Cells [" License"]。Value = day +" /" +月+"/" +年;

啰嗦但它确实有效!  根据文件 


https://msdn.microsoft.com/en-us/library/system.datetime.toshortdatestring%28v=vs.110%29.aspx


.Date仅适用于当前的DateTime对象。  为什么?




解决方案

您好RichardDunneBSc,


感谢您发布此处。


此论坛是关于Visual Studio IDE的,由于您的问题与C#编程语言更相关,我们会帮助您将其移至C#编程语言论坛以获得更好的支持。


https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral


如果您有一些VS IDE问题,请随时与我们联系。我们将尽力为您提供解决方案。


感谢您的理解与合作。




A date type gets converted to DateTime when selected in SQL due to Convert.ToDateTime(), so when displaying the date in a DataGridView, I added .Date

DataGridview.Rows[x].Cells["ColumnName"].value = ListName[x].GetDate().date;

But this is showing the time 00:00:00.   Why?

I then tried

var Date = ListName[x].GetDate().ToShortDateString();
DataGridView.Rows[x].Cells["ColumnName"].value = Date;

 

This is also showing the time 00:00:00  

var year = ListName[x].GetDate().Year;
var month = ListName[x].GetDate().Month;
var day = ListName[x].GetDate().Day;
DataGridView.Rows[x].Cells["Licence"].Value = day + "/" + month + "/" + year;

Long-winded but it works!  According to the documentation 

https://msdn.microsoft.com/en-us/library/system.datetime.toshortdatestring%28v=vs.110%29.aspx

.Date only works with the current DateTime object.  Why?

解决方案

Hi RichardDunneBSc,

Thanks for posting here.

This forum is about the Visual Studio IDE, as your issue is more related to the C# programming language, we help you move it to the C# programming language forum for better support.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral

If you have some VS IDE problems, please feel free to contact us. We will try our best to give you a solution.

Thanks for your understanding and cooperation.


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

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