如何从数据网格中的vb.net中的datetime中删除时间 [英] how to remove time from datetime in vb.net inside a datagrid

查看:72
本文介绍了如何从数据网格中的vb.net中的datetime中删除时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从数据网格中的vb.net中的datetime中删除时间

how to remove time from datetime in vb.net inside a datagrid

推荐答案

您编写的代码只显示您想要查看的位。如果这是ASP.NET,你创建一个模板来定义用于显示元素的代码,我不确定winforms。正如有人说'ToShortDateString'会这样做。
You write code to show just the bit you want to see. If this is ASP.NET, you create a template which defines the code used to show the element, I'm not sure about winforms. As someone said 'ToShortDateString' will do it.


你好,

你需要这样的东西。




you need something like this.

Dim dt As DateTime = DateTime.ParseExact(yourObject.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)

Dim s As String = dt.ToString("dd/M/yyyy")





问候

Sarva



regards
Sarva


很大程度上取决于你如何将数据绑定到网格。如果你有 AutoGenerateColumns = False ,那很简单:

A lot depends on how you are binding your data to the grid. If you have AutoGenerateColumns = False, it is pretty easy:
<Columns>
    <asp:BoundField DataField="DateSent" HeaderText="Date" ReadOnly="true" 

                HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" />
</Columns>

这告诉ASP使用指定的格式字符串。 HtmlEncode 需要关闭以使其正常工作,否则ASP可以通过导致不良结果的方式重新解释您的格式字符串。



还有其他方法可以做到这一点,但这可能会满足您的需求。

This tells ASP to use the specified format string. HtmlEncode needs to turned off for this to work, otherwise ASP can re-interpret your format string in ways leading to undesirable results.

There are other ways you can do this, but this will probably meet your needs.


这篇关于如何从数据网格中的vb.net中的datetime中删除时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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