开发者

string to date time "hh:mm:ss" or "dd.mm.yyyy hh:mm:ss" format

I try to convert a string like "hh:mm:ss" or "dd.mm.yyyy hh:mm:ss" but I didn't accomplish :( Code lik开发者_StackOverflow社区e that :

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);

but it didn't work..Any suggestion?


You are doing everything in a correct way, but perhaps you need not hh but HH like this:

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

hh is for 12-hour format, and looks like you are parsing from 24-hour format, so you need HH.


This site has several examples of string formatting and time/date formats.

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();

// Gives you "Monday, 27 December 2010"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜