我们可以转换此dateTime格式"IST 2010年9月23日19:34:06 "mm/dd/yyyy" C#格式 [英] Can we Convert this dateTime format " Thu Sep 23 19:34:06 IST 2010" to " mm/dd/yyyy" format in C#

查看:106
本文介绍了我们可以转换此dateTime格式"IST 2010年9月23日19:34:06 "mm/dd/yyyy" C#格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


如何将此"Thu Sep 23 19:34:06 IST 2010"日期时间格式转换为mm/dd/yyyy(US)格式.它是有效的日期时间格式吗?如果是如何将其转换为美国日期时间格式.


请通过C#代码帮助我.

hi all,


How to convert this " Thu Sep 23 19:34:06 IST 2010" date Time Format into mm/dd/yyyy(US) Format. Is it a Valid Date Time Format. If it is How to convert this into US date Time Format.


Please Help Me through C# Code.

推荐答案

这应该可以解决问题:
That should do the trick:
string time = "Thu Sep 23 19:34:06 IST 2010";
string pattern = "ddd MMM d HH:mm:ss IST yyyy";
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime timeVal;
bool bSuccess = DateTime.TryParseExact(time, pattern, culture, DateTimeStyles.AllowWhiteSpaces, out timeVal);
MessageBox.Show(timeVal.ToString("MM/dd/yyyy"));


首先从您拥有的此可用字符串中创建一个datetime对象,然后to字符串具有一个重载版本,该版本需要将格式转换为该格式,您可以使用

First create a datetime object from this available string you have and then the to string has an overloaded version which takes the format to convert to, you can use

DateTime.Now.ToString("MM/dd/yyyy");



经历这个-
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]
Hi,
Go through this-
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


这篇关于我们可以转换此dateTime格式"IST 2010年9月23日19:34:06 "mm/dd/yyyy" C#格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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