C# 如何在asp.net中更改日期格式

C# 如何在asp.net中更改日期格式,c#,asp.net,datetime,C#,Asp.net,Datetime,如何在asp.net中将日期时间格式2011-09-01 09:39:23更改为2011-Aug-01 09:39:23 我正在使用这个日期时间;要获取日期时间,但我希望它是2011-Aug-01 09:39:23格式,怎么做 我将日期时间设置为 字符串now=DateTime.now.ToString(“dd-MMM-yyy-hh:mm:ss”) 两者都不起作用 param[1] = new MySqlParameter("@Created", MySqlDbType.DateTime);

如何在asp.net中将日期时间格式2011-09-01 09:39:23更改为2011-Aug-01 09:39:23

我正在使用这个日期时间;要获取日期时间,但我希望它是2011-Aug-01 09:39:23格式,怎么做

我将日期时间设置为 字符串now=DateTime.now.ToString(“dd-MMM-yyy-hh:mm:ss”)

两者都不起作用

 param[1] = new MySqlParameter("@Created", MySqlDbType.DateTime);
        param[1].Value = now;
        command.Parameters.AddWithValue("@Created", now);
        param[2] = new MySqlParameter("@Modified", MySqlDbType.DateTime);
        param[2].Value = DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss"); 
        command.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss"));
你会发现有用的

更具体地说,您需要:

yourDate.toString("yyyy-MMM-dd hh:mm:ss");
DateTime.Now.ToString(“yyyy-MMM-dd-hh:mm:ss”)

if (IsPostBack)
{
    txtrcptdate.Text = DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss ");
}