Adding "de" to es-ES CultureInfo DateTime C #
Probably a dumb question, but I haven't worked with Culture before. The assets for the date must be:
MMMM dd "de" yyyy (without quotes on "de").
junio 1 de 2015
What I have now:
CultureInfo ci = new CultureInfo("es-ES", false);
string date = DateTime.Now.ToString("MMMM dd REPLACE yyyy", ci).Replace("REPLACE", "de");
I want to know if there is a "more programmatically correct" way to do this that I am not aware of, not about string.Replace
source to share
Just quote the literal part with single quotes, double quotes, or escape each backslash character:
string date = DateTime.Now.ToString("MMMM dd 'de' yyyy", ci);
string date = DateTime.Now.ToString("MMMM dd \"de\" yyyy", ci);
string date = DateTime.Now.ToString(@"MMMM dd \d\e yyyy", ci);
Note that in the second option, we need to escape "
inside the string literal, and in the third option, I use the string literal to avoid escaping backslashes. Using single quotes is the easiest :)
Read Custom Date and Time Format Strings for more details on what you can do.
source to share
If I understand clearly, you can escape the part de
with a single quote like:
string date = DateTime.Now.ToString("MMMM dd 'de' yyyy", ci);
or with a double quote;
string date = DateTime.Now.ToString("MMMM dd \"de\" yyyy", ci);
or escaped as a verbatim string literal ;
string date = DateTime.Now.ToString(@"MMMM dd \d\e yyyy", ci);
I almost prefer to use a single quote, because "
, and \
can be confusing.
Additional Information:
source to share