【问题标题】:ASP .NET C# - Format a MySQL date field properly in a listviewASP .NET C# - 在列表视图中正确格式化 MySQL 日期字段
【发布时间】:2009-09-14 18:31:39
【问题描述】:

我的 MySQL 数据库有一个日期字段,格式如下:

yyyy-mm-dd

但在 ASP .NET 中显示为:

2009 年 9 月 14 日上午 12:00:00

在 ItemTemplate 和 EditItemTemplate 中。

如何格式化字段以正确显示?

【问题讨论】:

    标签: c# asp.net mysql


    【解决方案1】:

    您可以使用 DateTime 的 ToShortDateString() 方法。 你也可以使用这样的东西:

    DateTime dateTimeObject = Convert.ToDateTime("9/14/2009 12:00:00 AM");
    dateTimeObject.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
    

    【讨论】:

      【解决方案2】:
          DateTime dt = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
          qry = "select taxpercentage from tbl_tax where effectivedate contains '" + dt+ "'";
          con.returnscalar(qry); what is wrong in this
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-18
        • 1970-01-01
        • 2013-03-21
        • 2020-11-24
        • 2018-04-03
        • 1970-01-01
        相关资源
        最近更新 更多