C# 字符串“截止日期时间”;hh:mm:ss“;或;年月日hh:mm:ss“;格式
我尝试转换字符串,如“hh:mm:ss”或“dd.mm.yyyyy hh:mm:ss”,但我没有完成:( 代码如下:C# 字符串“截止日期时间”;hh:mm:ss“;或;年月日hh:mm:ss“;格式,c#,parsing,datetime,C#,Parsing,Datetime,我尝试转换字符串,如“hh:mm:ss”或“dd.mm.yyyyy 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); 但是
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
而是hh
像这样:
tarihSaat[0] = DateTime.ParseExact(c, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);
hh
用于12小时格式,看起来您是从24小时格式解析的,因此需要hh
using System;
using System.Globalization;
DateTime.Parse("27.12.2010 00:00:00",
new CultureInfo("en-GB")).ToLongDateString();
//给你“2010年12月27日星期一”你的代码示例对我来说运行得很好-你确定
documentRowCount
是>0吗?它到底是怎么运行的?你得到了错误的值吗?它崩溃了吗?你能告诉我们程序正在做什么吗?它是否引发异常?它是否生成了错误的日期?