datetime.parse并使其与特定的格式工作 [英] datetime.parse and making it work with a specific format

查看:111
本文介绍了datetime.parse并使其与特定的格式工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件回来格式日期时间:


  

20080916 11:02



  

YYYYMM HH:SS


我怎样才能获得datetime.parse功能拿起这个?即分析它不示数?
干杯


解决方案

  DateTime.ParseExact(输入YYYYMMDD HH:MM,NULL);

假设你意思是说,分钟,随后的时间,而不是秒 - 你的例子是有点混乱。

借助 ParseExact文档详情其他重载,在如果你想有解析自动转换为通用时间或类似的东西。

作为@ 乔尔Coehoorn 提到,这里还有使用的选项<一个href=\"http://msdn.microsoft.com/en-us/library/system.datetime.tryparseexact(VS.80).aspx\">TryParseExact,它会返回一个布尔值,指示操作是成功还是失败 - 我仍然在NET 1.1,所以我经常忘记这一个。

如果您需要解析等格式,你可以检查出标准的DATETIME格式弦乐的。

I have a datetime coming back from an XML file in the format:

20080916 11:02

as in

yyyymm hh:ss

How can i get the datetime.parse function to pick up on this? Ie parse it without erroring? Cheers

解决方案

DateTime.ParseExact(input,"yyyyMMdd HH:mm",null);

assuming you meant to say that minutes followed the hours, not seconds - your example is a little confusing.

The ParseExact documentation details other overloads, in case you want to have the parse automatically convert to Universal Time or something like that.

As @Joel Coehoorn mentions, there's also the option of using TryParseExact, which will return a Boolean value indicating success or failure of the operation - I'm still on .Net 1.1, so I often forget this one.

If you need to parse other formats, you can check out the Standard DateTime Format Strings.

这篇关于datetime.parse并使其与特定的格式工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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