解析日期时间奇格式 [英] Parse DateTime From Odd Format

查看:111
本文介绍了解析日期时间奇格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
解析复杂的字符串作为日期时间

我有随着时间的字符串日期,我想解析成日期时间。我不太确定如何处理它,因为奇格式。 。帮助表示赞赏

I have a string date with time that I'd like to parse into a DateTime. I'm not quite sure how to tackle it because of the odd format. Help is appreciated.

例如:星期一3月24日13-42-30 2008

Example: Mon Mar 24 13-42-30 2008

推荐答案

DateTime.ParseExact 应该做你想要什么:

var dateTime = DateTime.ParseExact(
    "Mon Mar 24 13-42-30 2008",
    "ddd MMM dd HH-mm-ss yyyy",
    CultureInfo.CurrentCulture);



谁能告诉我两者的区别: CultureInfo.CurrentCulture CultureInfo.InvariantCulture ,像其他的答案?我是假设的东西,如一天名称和月份名称可能需要用自己的母语来进行解析。谢谢你。

Can someone tell me the difference between using CultureInfo.CurrentCulture and CultureInfo.InvariantCulture, like the other answers? I was assuming things like the day name and month name might need to be parsed in their native language. Thanks.

这篇关于解析日期时间奇格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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