Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get culture-specific date with 2 digit year in C#

I'm updating some code that formats a date to a string using "MM/dd/yy". I need it to be culture aware, but want to keep the two digit year in order to keep the date short. Below is what I came up with, but is there a better way?

string dateFormat = culture_Info.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy");
like image 847
xr280xr Avatar asked Jan 25 '12 17:01

xr280xr


People also ask

How to convert 2 digit year to 4 digit year in c#?

To convert 2-digit year into a 4-digit year, use the ToFourDigitYear method inside your current culture's calendar. But, if you're working with a string containing a date, create a custom CultureInfo instance and set the maximum year to 2099. After that, parse the string holding the date with the custom culture.

What is fff in date format?

The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.

What is en US date format?

The United States is one of the few countries that use “mm-dd-yyyy” as their date format–which is very very unique! The day is written first and the year last in most countries (dd-mm-yyyy) and some nations, such as Iran, Korea, and China, write the year first and the day last (yyyy-mm-dd).


1 Answers

I don't know of any way, no (and I've looked at the formatting reasonably extensively). What you've got obviously still leaves a bit of a nasty taste in the mouth, but I think it's the best you can do.

like image 135
Jon Skeet Avatar answered Sep 27 '22 19:09

Jon Skeet