如何在asp.net中以DD MM YYYY格式显示日期月份年 [英] How to display date month year in DD MM YYYY format in asp.net
问题描述
亲爱的朋友,
在我的数据库表中.我总是有一列,它将显示日期为2012年10月14日02:07:42 PM
我无法更改数据库中的日期时间,
所以在我的asp.net网页上,我想将其显示为14/10/2012 02:07:42 PM
它应为dd/mm/yyyy格式.
在我的网页上,我将标签命名为lblUpdate
这是我的代码.
这里,TimeLupdate是列名,TimeLastUpdate是表名
PageLoad
=========
Dear Friends,
In my database table. I have a column always it will be display date as 10/14/2012 02:07:42 PM
I cannot change Date time in my database,
So on my asp.net webpage I want to display it as 14/10/2012 02:07:42 PM
it should be in dd/mm/yyyy format.
on my webpage i took a label as lblUpdate
This is my code.
here TimeLupdate is column name and TimeLastUpdate is Table Name
PageLoad
=========
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Select TimeLupdate from TimeLastUpdate ";
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
lblUpdate.Text = reader["TimeLupdate "].ToString();
lblUpdate.ForeColor = Color.Red;
}
}
请帮助我将其显示为DD/MM/YYY和时间
在此先谢谢您.
Please help i want to display it as DD/MM/YYY and time
Thanks in advance.
推荐答案
尝试一下,希望对您有所帮助.
Try this, May it will help you.
Using Globalization;
CultureInfo ci=new CultureInf("gu-IN");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Select TimeLupdate from TimeLastUpdate ";
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
lblUpdate.Text = DateTime.ParseExact(reader["TimeLupdate "].ToString(),ci);
lblUpdate.ForeColor = Color.Red;
}
}
谢谢
Thanks
嗨 试试这个会起作用的
Hi Try this it will work
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Select TimeLupdate from TimeLastUpdate ";
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
lblUpdate.Text =string.Format("{0:M/d/yyyy}", reader["TimeLupdate"].ToString();
lblUpdate.ForeColor = Color.Red;
}
}
尝试一下:
Try this:
string date = "10/14/2012";
int year = Convert.ToInt32(date.Split('/')[2]);
int day = Convert.ToInt32(date.Split('/')[1]);
int month = Convert.ToInt32(date.Split('/')[0]);
DateTime dtOld = new DateTime(year, month, day);
string newDate = dtOld.ToString("dd/MM/yyyy hh:mm:ss tt").Replace('-', '/');
--Amit
--Amit
这篇关于如何在asp.net中以DD MM YYYY格式显示日期月份年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!