Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") does not account my format

This is the code I have:

DateTime.Now.AddMinutes(55).ToString("dd/MM/yyyy HH:mm:ss")

The string I get from that code is:

"16.09.2013 19:45:03"

The question is, why the string is not in the format I've provided?

like image 373
Doctorslo Avatar asked Sep 16 '13 09:09

Doctorslo


People also ask

How do I change the date format in ToString?

To do this, you use the "MM/yyyy" format string. The format string uses the current culture's date separator. Getting a string that contains the date and time in a specific format. For example, the "MM/dd/yyyyHH:mm" format string displays the date and time string in a fixed format such as "19//03//2013 18:06".


1 Answers

Use this:

DateTime.Now.AddMinutes(55).ToString("dd'/'MM'/'yyyy HH:mm:ss")

because / means default date separator, so it's associated with your current culture. So know it will use always / here, no matter of current culture.

Read more here at MSDN

like image 180
Kamil Budziewski Avatar answered Sep 21 '22 15:09

Kamil Budziewski