将字符串Fri Jul 11​​ 00:00:00 UTC + 0800 2014转换为vb.net mvc 5中的datetime [英] Convert string Fri Jul 11 00:00:00 UTC+0800 2014 to datetime in vb.net mvc 5

查看:103
本文介绍了将字符串Fri Jul 11​​ 00:00:00 UTC + 0800 2014转换为vb.net mvc 5中的datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨先生/ s,



美好的一天。



我很难过找到这个日期字符串到日期时间的转换

在vb.net中mvc 5

这是我的样本字符串日期:



Hi Sir/s,

Good day.

I'm having a hard time on finding conversion of this date string to date time
in vb.net mvc 5
Here's my sample string date:

Fri Jul 11 00:00:00 UTC+0800 2014





我想转换这个字符串到日期时间值



我做了这个解决方案,但我仍然收到这个错误:





I would like to convert this string to datetime value

I made this solution but still I'm getting this error:

String was not recognized as a valid DateTime.





这是我在vb.net中的现有代码





Here's my existing code in vb.net

'Dim datestring As [String] = "Fri Jul 11 00:00:00 UTC+0800 2014"
                   Dim datestring As [String] = descriptor.Value.ToString
                   Dim d = datestring.Split(New Char() {" "c}, 5).Take(4)
                   Dim dt As DateTime = DateTime.Parse(d.Aggregate(Function(x, y) x + " " + y))
                   descriptor.Value = dt











我希望有人可以帮助我。提前谢谢...






I hope someone could help me. Thank you in advance...

推荐答案

尝试使用DateTime.TryParseExact:

Try using DateTime.TryParseExact:
Dim [date] As String = "Fri Jul 11 00:00:00 UTC+0800 2014"
Dim dat As DateTime
If DateTime.TryParseExact([date], "ddd MMM dd HH:mm:ss 'UTC'zzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, dat) Then
    Console.WriteLine(dat)
End If

按字符串化UTC指标并添加zzzUTC-plus-offset代码做你想做的事。

By "stringifying" the UTC indicator and adding the "zzz" UTC-plus-offset code it shoudl do what you want.


这篇关于将字符串Fri Jul 11​​ 00:00:00 UTC + 0800 2014转换为vb.net mvc 5中的datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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