仅显示日期,不显示日期时间 [英] Display only date not datetime

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

问题描述

在CustomersBusinessObject中,我是这样的.

in CustomersBusinessObject i have like this.

interface CustomersInterface


{


{

DateTime joiningdate
        {
            get;
            set;
        }
}



公共类的客户:ICustomersInterface
{



public class Customers : ICustomersInterface
{

public DateTime joiningdate
        {
            get
            {
                return _date;
            }
            set
            {
                _date = value;
            }
        }



}

在DAL中

公开列表<客户> getcustomers()
{

试试
{
列表<客户> lstcustomers =新列表< customers>();
SqlConnection con =新的SqlConnection(constring);
cmd = new SqlCommand("SELECT empid,empname,departmentid,joiningdate,locationid,salary,jobid,Isworking from employee",con);
con.Open();
dr = cmd.ExecuteReader();
如果(dr.HasRows)
{
while(dr.Read())
{
客户cst =新客户();
cst.employeeid =(int)dr [0];
cst.empname =(string)dr [1];
cst.departmentid =(int)dr [2];
cst.joiningdate =(DateTime)dr [3];
cst.locationid =(int)dr [4];
cst.salary =(int)dr [5];
cst.jobid =(int)dr [6];
cst.isworking =(bool)dr [7];
lstcustomers.Add(cst);
}
}
返回lstcustomers;
}
catch(ex ex例外)
{
投掷;
}
在这里我只想显示日期,但它是即将到来的日期时间
我应该在哪里修改,请帮助我
谢谢.



}

in DAL

public List<customers> getcustomers()
{

try
{
List<customers> lstcustomers = new List<customers>();
SqlConnection con = new SqlConnection(constring);
cmd = new SqlCommand("SELECT empid, empname,departmentid, joiningdate, locationid, salary, jobid, Isworking from employee", con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Customers cst = new Customers();
cst.employeeid = (int)dr[0];
cst.empname = (string)dr[1];
cst.departmentid = (int)dr[2];
cst.joiningdate = (DateTime)dr[3];
cst.locationid = (int)dr[4];
cst.salary = (int)dr[5];
cst.jobid = (int)dr[6];
cst.isworking = (bool)dr[7];
lstcustomers.Add(cst);
}
}
return lstcustomers;
}
catch (Exception ex)
{
throw;
}
here i want to display only date but it is coming datetime
where i should modify please help me
thank you.

推荐答案

您没有说过如何在某种日期控件中以简单的字符串形式显示数据吗?

假设它是字符串,则可以使用

You don''t say HOW you are displaying the data, as a simple string, in some sort of date control?

Assuming it is as a string, then you can use

cst.Joiningdate.toString("dd/mm/yyyy")



例如



for example


请参见System.DateTime.String方法: http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ];
首先,这是一个: http://msdn.microsoft.com/en-us/library/zdtaw1bw .aspx [^ ] .

学习格式字符串:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ].

就这样.

—SA
See System.DateTime.String methods: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^];
first of all, this one: http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^].

Learn format strings:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^].

That''s it.

—SA




我认为您的代码中不应做任何修改.我认为您应该考虑使用格式来显示这样的内容...
示例:
Hi,

I think there should no any modification to do in your code. In my opinion you should consider using format to display such...
Example:
DateTime date1 = new DateTime(2008, 4, 10);
Console.WriteLine(date1.ToString("D", 
CultureInfo.CreateSpecificCulture("en-US")));
// Displays Thursday, April 10, 2008                        
Console.WriteLine(date1.ToString("D", 
CultureInfo.CreateSpecificCulture("pt-BR")));
// Displays quinta-feira, 10 de abril de 2008                        
Console.WriteLine(date1.ToString("D", 
CultureInfo.CreateSpecificCulture("es-MX")));
// Displays jueves, 10 de abril de 2008   



您可以参考此



You may refer into this

Standard Date and Time Format Strings


链接


link


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

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