cant format datetime using dataformatstring

2019-04-29 19:12发布

问题:

For some reason i can not format the text of my date in a gridview

<asp:BoundField DataField="deptdate" HeaderText="Departure Date" dataformatstring="{0:ddd, MM/d/yyyy}" htmlencode="False" SortExpression="deptdate" />

I still get this:

May 10 2011 12:00AM

I DID NOT SET MY FIELD TO DATETIME IN THE DATABASE...DOY

回答1:

Have you tried this approach?

http://peterkellner.net/2006/05/24/how-to-set-a-date-format-in-gridview-using-aspnet-20using-htmlencode-property/

<asp id="GridView1" runat="server" :GridView>
<columns>
  <asp headertext="CreationDate" dataformatstring="{0:M-dd-yyyy}" 
       datafield="CreationDate" :BoundField HtmlEncode="false" />
</columns>


回答2:

You can use DataFormatString="{0:d}" for short date format in your column definition.



回答3:

Since Q2 2013 the RadHtmlChart can be databound to DateTime objects, so that XAxis Labels, Series Labels and ToolTips can be formatted to the desired date format. More information on formatting dates is available in Date Axis article: http://www.telerik.com/help/aspnet-ajax/htmlchart-date-axis.html