如何在c#中将datetime转换为date [英] How to convert datetime to date in c#
本文介绍了如何在c#中将datetime转换为date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void BindData()
{
string strFirstName = "";
string strLastName="";
DateTime? dtStartDate = null;
DateTime? dtEndDate = null;
var PatientEvaluations = objPatient.GetAllPatientEvaluation(strFirstName,strLastName,dtStartDate,dtEndDate).AsQueryable();
GridViewPatient.DataSource = PatientEvaluations;
GridViewPatient.DataBind();
}
这是我的方法
在数据库中start和endDate值是12/12/1988
但是当这个方法绑定到我的网格时它会显示
12/12/1988 12:00:00 AM
plz帮帮我
i想要显示
12/12/1988
this is my method
in database the start and endDate value is 12/12/1988
but when this method bind into my grid it display
12/12/1988 12:00:00AM
plz help me
i want to display
12/12/1988
推荐答案
在.NET中没有日期这样的东西。但是,有一个函数Date
,它返回与参数相同的时间,当天的时间只是截断到午夜的12:00:00:
http://msdn.microsoft.com/en-us/library/system .datetime.date.aspx [ ^ ]。
我相信你不需要它。您唯一的问题是您尝试仅在屏幕上显示日期,但也会显示时间。您只需要学习一般的格式,对于这种类型:
http: //msdn.microsoft.com/en-us/library/ht77y576.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ],
http: //msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]。
就是这样。
-SA
There is no such thing as just date in .NET. However, there is a functionDate
which returns the same time as argument, with time of the day simply "truncated" to 12:00:00 midnight:
http://msdn.microsoft.com/en-us/library/system.datetime.date.aspx[^].
I believe you don''t need it. Your only problem is that you try to show only the date on screen, but the time is also shown. You just need to learn formatting in general, and for this type:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^],
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].
That''s it.
—SA
<div class="right" style="width: 166px; height: 19px;">
<%# Eval("EvaluationDate", "{0:M-dd-yyyy}")%></div>
i在我的网格视图中使用它来解决它
i solve it using this in my grid view
protected void BindData()
{
string strFirstName = "";
string strLastName="";
DateTime? dtStartDate = null;
DateTime? dtEndDate = null;
var PatientEvaluations = objPatient.GetAllPatientEvaluation(strFirstName,strLastName,dtStartDate.ToString("dd/MM/yyyy"),dtEndDate.ToString("dd/MM/yyyy")).AsQueryable();
GridViewPatient.DataSource = PatientEvaluations;
GridViewPatient.DataBind();
}
你试试这个,希望它能给你想要的结果。
You try this, hope it will give expected result what you needed.
这篇关于如何在c#中将datetime转换为date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文