如何在Asp.net中更改日期格式 [英] How to change date format in Asp.net

查看:73
本文介绍了如何在Asp.net中更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在文本框中具有价值,2011年7月15日星期五19:22:31 并希望更改日期齿格式.

请帮忙.

谢谢
莫哈末wasif

Hi All ,

I have value in textbox as Fri Jul 15 19:22:31 2011
and wan to change in date tine format .

Please help.

Thanks
Mohd. wasif

推荐答案

如果您使用的是简单的datetime函数,则写为::
if you are using simple datetime function then write as::
DateTime.Now.ToString("dd/MM/yyyy");


如果您使用压光机控制,则写为:


and if you are using calender control then write as:

string date = Calendar1.SelectedDate.ToString("dd/MM/yyyy");



但请记住,特定列的数据类型应为vaerchar



but remember that datatype of particular column should be vaerchar


这些链接包含不同的日期格式
选择您想要的那个

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]

http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8- F859AA20581F.htm [ ^ ]
These links contains different date formats
choose the one which you want

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]

http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm[^]




尝试使用此代码转换时间格式

Hi,

try this code for converting time format

string dfrmt = "Fri Jul 15 19:22:31 2011";
         string[] sd = dfrmt.Split(' ');
         string dt = System.DateTime.Now.ToString();
         int month = DateTime.Parse("1." + sd[1] + " 2008").Month;

         DateTime dth = new DateTime(int.Parse(sd[4]), month, int.Parse(sd[2]), int.Parse(sd[3].Split(':')[0]), int.Parse(sd[3].Split(':')[1]), int.Parse(sd[3].Split(':')[2]));

         string st = month  + "/" + sd[2] + "/" + sd[4] + " " + dth.ToLocalTime().ToLongTimeString();



通过使用此代码,您可以转换所需的日期时间格式

最好的



By using this code you can convert your required datetime format

All the Best


这篇关于如何在Asp.net中更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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