String before date "hh: mm: ss" or "dd.mm.yyyy hh: mm: ss" format

I am trying to convert a string like "hh: mm: ss" or "dd.mm.yyyy hh: mm: ss", but I did not execute :( Code like this:

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?

+4
source share
3 answers

You are doing everything right, but maybe you don't need hh , but hh :

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

hh designed for a 12 hour format and looks like you are dealing with a 24 hour format, so you need hh .

+8
source

This site provides some examples of formatting strings and time and date formats.

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

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

// Gives you "Monday December 27, 2010"

0
source

Source: https://habr.com/ru/post/1347128/


All Articles