I have the date format string dd-mm-yy. Please can you tell me how to add hours and minutes to the string (i.e 13-03-2010.21.03) ....
DateTime.Today.ToString("dd-mm-yy") ?
I have the date format string dd-mm-yy. Please can you tell me how to add hours and minutes to the string (i.e 13-03-2010.21.03) ....
DateTime.Today.ToString("dd-mm-yy") ?
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.
Note that the format string you first used is incorrect, as mm
stands for minutes so you should have used MM
for months.
You are also using Today
, which does not have the time component (so it would always be 00:00:00). If you need those (hours, minutes, seconds and milliseconds), you should use Now
.
please check this 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)
DateTime.Now.ToString("dd-MM-yyyy.HH.mm");
mm
is minutes, MM
is months, so your current example is wrong.
Also, note that you need to use Now
rather than Today
, otherwise it'll always be 00.00
DateTime.Now.ToString("dd-MM-yy.HH.mm");
MM for Months mm for minutes
DateTime.Now.ToString("dd-MM-yy.HH.mm")
Change the Today to Now
Please note that mm = minutes and MM = months