繁体   English   中英

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

[英]string to date time “hh:mm:ss” or “dd.mm.yyyy hh:mm:ss” format

我尝试转换像“hh:mm:ss”或“dd.mm.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但是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();

//给你“2010年12月27日星期一”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM