DateTime只是日期? [英] DateTime just the date?

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

问题描述

解决问题我只知道如何使用DateTime显示我的结果,如下所示:

Getting abit of a problem I only know how to use DateTime to display my results like so:

    {

            string uri = "http://localhost:8002/Service/HireDate";
            XDocument xDoc = XDocument.Load(uri);
            var staff = xDoc.Descendants("HireDate")
                .Select(n => new
                {
                    StartDate = DateTime.Parse(n.Element("HireFromDate").Value), //this line
                    EndDate = DateTime.Parse(n.Element("HireToDate").Value), //this line
                    TotalDaysHired = n.Element("NumberOfDaysHired").Value,
                })
                .ToList();

            dataGrid9.ItemsSource = staff;

    }

但是在我的datagrid中输出如下:

However this outputs like this in my datagrid:

15/07/2012 00:00:00
27/07/2012 00:00:00

有没有办法删除我只想要日期的时间?

Is there a way to remove the time I just want the date?

推荐答案

所以你只想显示一个 DateTime Date > as String ?您可以使用 DateTime.ToShortDateString() ,这是最可读的:

So you want to show only the Date part of a DateTime as String? You could use DateTime.ToShortDateString() which is most readable:

StartDate = DateTime.Parse(n.Element("HireFromDate").Value).ToShortDateString()

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

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