DateTime standard format for day, month and year
up vote
0
down vote
favorite
Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"
Just to display day and month like this, I know I can use "M" standard format string.
But how I can write "November 22, 2018" ?
Do I need to concatenate two strings like this:
$"{dt.ToString("M")}, {dt.ToString("yyyy")}"
Is there another way?
c# .net
|
show 12 more comments
up vote
0
down vote
favorite
Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"
Just to display day and month like this, I know I can use "M" standard format string.
But how I can write "November 22, 2018" ?
Do I need to concatenate two strings like this:
$"{dt.ToString("M")}, {dt.ToString("yyyy")}"
Is there another way?
c# .net
1
So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36
Every country with its own format
– Don Box
Nov 22 at 16:39
But just day month and year
– Don Box
Nov 22 at 16:39
What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40
2
It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40
|
show 12 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"
Just to display day and month like this, I know I can use "M" standard format string.
But how I can write "November 22, 2018" ?
Do I need to concatenate two strings like this:
$"{dt.ToString("M")}, {dt.ToString("yyyy")}"
Is there another way?
c# .net
Is there any standard DateTime format for showing "[day] [month] [year]"?
I do not wish to use custom format strings, because it takes away the ability to have order of "day" and "month" depending on the country.
For example, for "en-us" it's "November 22", in France day is first, so it's "22 Novembre"
Just to display day and month like this, I know I can use "M" standard format string.
But how I can write "November 22, 2018" ?
Do I need to concatenate two strings like this:
$"{dt.ToString("M")}, {dt.ToString("yyyy")}"
Is there another way?
c# .net
c# .net
asked Nov 22 at 16:33
Don Box
905721
905721
1
So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36
Every country with its own format
– Don Box
Nov 22 at 16:39
But just day month and year
– Don Box
Nov 22 at 16:39
What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40
2
It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40
|
show 12 more comments
1
So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36
Every country with its own format
– Don Box
Nov 22 at 16:39
But just day month and year
– Don Box
Nov 22 at 16:39
What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40
2
It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40
1
1
So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36
So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36
Every country with its own format
– Don Box
Nov 22 at 16:39
Every country with its own format
– Don Box
Nov 22 at 16:39
But just day month and year
– Don Box
Nov 22 at 16:39
But just day month and year
– Don Box
Nov 22 at 16:39
What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40
What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40
2
2
It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40
It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40
|
show 12 more comments
4 Answers
4
active
oldest
votes
up vote
2
down vote
It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern
and strip out any occurrence of "dddd" (and its surrounding space/punctuation).
That should give you the variation you want across cultures while removing the weekday.
Examples:
en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018
fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018
add a comment |
up vote
1
down vote
As I can understand the solution for your problem could be to create a new CultureInfo
object.
I've tested it.
CultureInfo us = new CultureInfo("en-US");
string usDate = us.DateTimeFormat.ShortDatePattern;
CultureInfo fr = new CultureInfo("fr-FR");
string frDate = fr.DateTimeFormat.ShortDatePattern;
Console.WriteLine(usDate);
Console.WriteLine(frDate);
//Apply the country format here.
var localDate = DateTime.Now.ToString(frDate);
Console.WriteLine(localDate);
So the format output will be as the location format you provide.
M/d/yyyy ---> USA format.
dd/MM/yyyy ---> France format.
22/11/2018 ---> France format applied to the current date.
For more information redirect to:
CultureInfo Class
add a comment |
up vote
0
down vote
$"{dt.ToString("MMMM dd, yyyy")}"
This will show it as November 22, 2018 assuming that dt is assigned this date.
Also, check out Custom Date Time Format String.
1
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
1
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
1
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
add a comment |
up vote
0
down vote
You can obtain the LongDatePattern
from the current culture, then remove the day-of-week (dddd
) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.
string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");
Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"
Now you have a custom format you can apply:
string s = DateTime.Now.ToString(modifiedDatePattern);
Console.WriteLine(s); // "November 22, 2018"
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern
and strip out any occurrence of "dddd" (and its surrounding space/punctuation).
That should give you the variation you want across cultures while removing the weekday.
Examples:
en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018
fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018
add a comment |
up vote
2
down vote
It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern
and strip out any occurrence of "dddd" (and its surrounding space/punctuation).
That should give you the variation you want across cultures while removing the weekday.
Examples:
en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018
fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018
add a comment |
up vote
2
down vote
up vote
2
down vote
It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern
and strip out any occurrence of "dddd" (and its surrounding space/punctuation).
That should give you the variation you want across cultures while removing the weekday.
Examples:
en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018
fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018
It does seem a little odd that the full option isn't available. The closest I can suggest is to use custom formatting, but rather than supply your own, grab DateTimeFormatInfo.LongDatePattern
and strip out any occurrence of "dddd" (and its surrounding space/punctuation).
That should give you the variation you want across cultures while removing the weekday.
Examples:
en-US => dddd, MMMM dd, yyyy => MMMM dd, yyyy => November 22, 2018
fr-FR => dddd d MMMM yyyy => d MMMM yyyy => 22 novembre 2018
answered Nov 22 at 16:50
sellotape
5,60021619
5,60021619
add a comment |
add a comment |
up vote
1
down vote
As I can understand the solution for your problem could be to create a new CultureInfo
object.
I've tested it.
CultureInfo us = new CultureInfo("en-US");
string usDate = us.DateTimeFormat.ShortDatePattern;
CultureInfo fr = new CultureInfo("fr-FR");
string frDate = fr.DateTimeFormat.ShortDatePattern;
Console.WriteLine(usDate);
Console.WriteLine(frDate);
//Apply the country format here.
var localDate = DateTime.Now.ToString(frDate);
Console.WriteLine(localDate);
So the format output will be as the location format you provide.
M/d/yyyy ---> USA format.
dd/MM/yyyy ---> France format.
22/11/2018 ---> France format applied to the current date.
For more information redirect to:
CultureInfo Class
add a comment |
up vote
1
down vote
As I can understand the solution for your problem could be to create a new CultureInfo
object.
I've tested it.
CultureInfo us = new CultureInfo("en-US");
string usDate = us.DateTimeFormat.ShortDatePattern;
CultureInfo fr = new CultureInfo("fr-FR");
string frDate = fr.DateTimeFormat.ShortDatePattern;
Console.WriteLine(usDate);
Console.WriteLine(frDate);
//Apply the country format here.
var localDate = DateTime.Now.ToString(frDate);
Console.WriteLine(localDate);
So the format output will be as the location format you provide.
M/d/yyyy ---> USA format.
dd/MM/yyyy ---> France format.
22/11/2018 ---> France format applied to the current date.
For more information redirect to:
CultureInfo Class
add a comment |
up vote
1
down vote
up vote
1
down vote
As I can understand the solution for your problem could be to create a new CultureInfo
object.
I've tested it.
CultureInfo us = new CultureInfo("en-US");
string usDate = us.DateTimeFormat.ShortDatePattern;
CultureInfo fr = new CultureInfo("fr-FR");
string frDate = fr.DateTimeFormat.ShortDatePattern;
Console.WriteLine(usDate);
Console.WriteLine(frDate);
//Apply the country format here.
var localDate = DateTime.Now.ToString(frDate);
Console.WriteLine(localDate);
So the format output will be as the location format you provide.
M/d/yyyy ---> USA format.
dd/MM/yyyy ---> France format.
22/11/2018 ---> France format applied to the current date.
For more information redirect to:
CultureInfo Class
As I can understand the solution for your problem could be to create a new CultureInfo
object.
I've tested it.
CultureInfo us = new CultureInfo("en-US");
string usDate = us.DateTimeFormat.ShortDatePattern;
CultureInfo fr = new CultureInfo("fr-FR");
string frDate = fr.DateTimeFormat.ShortDatePattern;
Console.WriteLine(usDate);
Console.WriteLine(frDate);
//Apply the country format here.
var localDate = DateTime.Now.ToString(frDate);
Console.WriteLine(localDate);
So the format output will be as the location format you provide.
M/d/yyyy ---> USA format.
dd/MM/yyyy ---> France format.
22/11/2018 ---> France format applied to the current date.
For more information redirect to:
CultureInfo Class
answered Nov 22 at 17:07
Angel Roma
13917
13917
add a comment |
add a comment |
up vote
0
down vote
$"{dt.ToString("MMMM dd, yyyy")}"
This will show it as November 22, 2018 assuming that dt is assigned this date.
Also, check out Custom Date Time Format String.
1
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
1
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
1
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
add a comment |
up vote
0
down vote
$"{dt.ToString("MMMM dd, yyyy")}"
This will show it as November 22, 2018 assuming that dt is assigned this date.
Also, check out Custom Date Time Format String.
1
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
1
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
1
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
add a comment |
up vote
0
down vote
up vote
0
down vote
$"{dt.ToString("MMMM dd, yyyy")}"
This will show it as November 22, 2018 assuming that dt is assigned this date.
Also, check out Custom Date Time Format String.
$"{dt.ToString("MMMM dd, yyyy")}"
This will show it as November 22, 2018 assuming that dt is assigned this date.
Also, check out Custom Date Time Format String.
answered Nov 22 at 16:47
Raarge
1912
1912
1
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
1
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
1
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
add a comment |
1
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
1
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
1
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
1
1
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
Thank you for your response. Please read the question carefully, I mentioned it has to take localization into account, I gave an example.
– Don Box
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
It seems like almost a correct answer for me, isn't it? It displays "[month] [day], [year]" in any current given culture, or any other culture, if specified as second parameter. Why "almost"? Because for Russian it says "ноября 22, 2018", which is gramatically incorrect.
– Yeldar Kurmangaliyev
Nov 22 at 16:52
1
1
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
My apologies, when i saw the question and answered things changed and I did not check to see if there had been any further entries before i posted. This was my fault.
– Raarge
Nov 22 at 16:54
1
1
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
@Raarge Humility from the very start. Gets my up-vote. Welcome to SO!
– Dan Rayson
Nov 22 at 16:58
add a comment |
up vote
0
down vote
You can obtain the LongDatePattern
from the current culture, then remove the day-of-week (dddd
) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.
string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");
Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"
Now you have a custom format you can apply:
string s = DateTime.Now.ToString(modifiedDatePattern);
Console.WriteLine(s); // "November 22, 2018"
add a comment |
up vote
0
down vote
You can obtain the LongDatePattern
from the current culture, then remove the day-of-week (dddd
) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.
string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");
Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"
Now you have a custom format you can apply:
string s = DateTime.Now.ToString(modifiedDatePattern);
Console.WriteLine(s); // "November 22, 2018"
add a comment |
up vote
0
down vote
up vote
0
down vote
You can obtain the LongDatePattern
from the current culture, then remove the day-of-week (dddd
) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.
string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");
Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"
Now you have a custom format you can apply:
string s = DateTime.Now.ToString(modifiedDatePattern);
Console.WriteLine(s); // "November 22, 2018"
You can obtain the LongDatePattern
from the current culture, then remove the day-of-week (dddd
) and surrounding characters with a regular expression. Below, I am assuming that commas, periods, and spaces are the only separators, but if you encounter others you may want to modify the regex accordingly.
string longDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;
string modifiedDatePattern = Regex.Replace(longDatePattern, @"[,.]?s?d{4}[,.]?s?", "");
Console.WriteLine(longDatePattern); // "dddd, MMMM d, yyyy"
Console.WriteLine(modifiedDatePattern); // "MMMM d, yyyy"
Now you have a custom format you can apply:
string s = DateTime.Now.ToString(modifiedDatePattern);
Console.WriteLine(s); // "November 22, 2018"
answered Nov 22 at 17:03
Matt Johnson
134k40273396
134k40273396
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435102%2fdatetime-standard-format-for-day-month-and-year%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
So what you want? "Day Month, Year", or every country with its own format?
– SeM
Nov 22 at 16:36
Every country with its own format
– Don Box
Nov 22 at 16:39
But just day month and year
– Don Box
Nov 22 at 16:39
What type is your project? WinForms, MVC, WPF..etc?
– SeM
Nov 22 at 16:40
2
It's WPF, but it shouldn't matter I think, it's NET
– Don Box
Nov 22 at 16:40