English 中文(简体)
时间问题
原标题:DateTime.ParseExact formats question
  • 时间:2009-11-25 16:30:17
  •  标签:
  • c#
  • datetime

我有眼光的时段:

“1 2009 2300”,“1 14 2009 0”, “1 14 2009 100

因此,我需要把时间划入。

我已尝试:

string[] sExpectedFormats = {"M d yyyy Hmm", "M d yyyy hmm", "M d yyyy 0"};
DateTime dtReportDateTime = DateTime.ParseExact(sReportDateTime, 
 sExpectedFormats, 
 System.Globalization.CultureInfo.InvariantCulture,
 System.Globalization.DateTimeStyles.None);

但它未能做到第三点“2009年1月14日100”。 我不清楚为此使用何种形式?

为了澄清,我把这一数据作为“1 14”和“100”时间段获取,因此,我可以将其整理成一个日期。

增 编

最佳回答

页: 1

坦率地说,我被诱惑,在平息之前进行体力改革,以便它总是在4位数而不是3位数中结束。 由于我通常建议他们,这同定期表达的工作一样:

我不敢肯定,为什么你拿走“H”和“h”两种格式——它从来不与第二种格式相匹配,因为对第二种方式来说,任何有效的话都是有效的。

如果你按照我前面的建议事先确定座右铭,那么你就只能使用。

{"M d yyyy HHmm", "M d yyyy 0"}
问题回答

我认为,它之所以失败,是因为“hmm” = “100”在 AM或PM之间含糊不清。 或许应该坚持“Hmm”或使用“hmm tt”=“100 AM”格式。

Edit:受审判和失败。 Jon在其答复和我的评论中所说的话是真实的。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签