字符串日期时间"hh:mm:ss"或“dd.mm.yyyy hh: mm: ss"格式

本文关键字:mm quot hh ss dd yyyy 格式 字符串 时间 日期 | 更新日期: 2023-09-27 17:49:00

我尝试转换像"hh:mm:ss"或"dd.mm. ss"这样的字符串。yyyy hh:mm:ss"但是我没有完成。代码如下:

public DateTime[] tarihSaat = new DateTime[documentRowCount]
string c = "27.12.2010 00:00:00"
tarihSaat[0] = DateTime.ParseExact(c, "dd.MM.yyyy hh:mm:ss", CultureInfo.InvariantCulture);

但它没有工作…有什么建议吗?

字符串日期时间"hh:mm:ss"或“dd.mm.yyyy hh: mm: ss"格式

你做的每件事都是正确的,但也许你不需要hh,但HH像这样:

tarihSaat[0] = DateTime.ParseExact(c, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);

hh是12小时格式,看起来你是从24小时格式解析,所以你需要HH

这个网站有几个字符串格式和时间/日期格式的例子。

http://blog.stevex.net/string-formatting-in-csharp/

using System;
using System.Globalization;
DateTime.Parse("27.12.2010 00:00:00", 
               new CultureInfo("en-GB")).ToLongDateString();

//显示"Monday, 27 December 2010"