DateTime format strings?

I have a dd-mm-yy date format. Please tell us how to add hours and minutes to a line (for example, 13-03-2010.21.03) ....

DateTime.Today.ToString("dd-mm-yy") ? 
+4
source share
5 answers

please check http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx and http://www.csharp-examples.net/string-format-datetime/ for more information

 String.Format("{0:d/M/yyyy HH:mm:ss}", datetime) 
+6
source
 DateTime.Now.ToString("dd-MM-yy.HH.mm") 

Change Today to Now

Note that mm = minutes and MM = months

+5
source

You can use this:

 DateTime.Now.ToString("dd-MM-yy.hh.mm") 

If you want 24 hours:

 DateTime.Now.ToString("dd-MM-yy.hh.mm") 

See the MSDN documentation.

Please note that the format string that you first used is incorrect, since mm stands for minutes, so you should have used mm for several months.

You also use Today , which does not have a time component (so it will always be 00:00:00). If you need those (hours, minutes, seconds and milliseconds), you should use Now .

+3
source
 DateTime.Now.ToString("dd-MM-yyyy.HH.mm"); 

mm is minutes, mm is months, so your current example is incorrect.

Also note that you need to use Now , not Today , otherwise it will always be 00.00

+2
source
 DateTime.Now.ToString("dd-MM-yy.HH.mm"); 

MM in months mm in minutes

+1
source

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


All Articles