Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 like 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?

like image 227
dnur Avatar asked Dec 27 '22 22:12

dnur


2 Answers

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.

like image 75
Dmitrii Lobanov Avatar answered Jan 15 '23 02:01

Dmitrii Lobanov


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

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

like image 29
John Batdorf Avatar answered Jan 15 '23 03:01

John Batdorf