Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get the users set of date format pattern strings?

88 views
Skip to first unread message

David Lowndes

unread,
Dec 30, 2009, 11:53:11 AM12/30/09
to
I would like to get the current user's set of date format pattern
strings - as listed in the Control Panel regional settings applet. For
my UK English system I see the following patterns listed:

Short Date:
dd/MM/yyyy
dd/MM/yy
d/M/yy
d.M.yy
yyyy-MM-dd

Long Date:
dd MMMM yyyy
d MMMM yyyy

If I use GetDateTimeFormats (d and D) the results match the expected
patterns above, but of course they're the formatted date not the
pattern string.

If I use GetAllDateTimePatterns (d and D) I only get 1 pattern
for both short & long formats.

FWIW, here's an example code snippet:

string [] formats =
System.DateTime.UtcNow.GetDateTimeFormats('d');
formats = System.DateTime.UtcNow.GetDateTimeFormats('D');
formats =
System.DateTime.UtcNow.GetDateTimeFormats(System.Globalization.CultureInfo.CurrentCulture);
System.Globalization.DateTimeFormatInfo dtfi = new
System.Globalization.DateTimeFormatInfo();
formats = dtfi.GetAllDateTimePatterns('d');
formats = dtfi.GetAllDateTimePatterns('D');

... and these are the string arrays returned:

GetDateTimeFormats('d'):
30/12/2009
30/12/09
30/12/09
30.12.09
2009-12-30

GetDateTimeFormats('D'):
30 December 2009
30 December 2009

GetAllDateTimePatterns('d'):
MM/dd/yyyy

GetAllDateTimePatterns('D'):
dddd, dd MMMM yyyy

How do you get the format strings that GetDateTimeFormats uses - they
appear to be what the OS uses, and are not what GetAllDateTimePatterns
returns.

Dave

Mihai N.

unread,
Dec 31, 2009, 3:35:41 AM12/31/09
to
> I would like to get the current user's set of date format pattern
> strings - as listed in the Control Panel regional settings applet. For
> my UK English system I see the following patterns listed:

http://msdn.microsoft.com/en-us/library/aszyst2c.aspx


--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

David Lowndes

unread,
Dec 31, 2009, 5:48:50 AM12/31/09
to
>> I would like to get the current user's set of date format pattern
>> strings - as listed in the Control Panel regional settings applet. For
>> my UK English system I see the following patterns listed:
>
>http://msdn.microsoft.com/en-us/library/aszyst2c.aspx

Hi Mihai,

As I mentioned in my original post, GetAllDateTimePatterns doesn't get
the patterns that the OS shows - which correspond to the ones that
GetDateTimeFormats uses.

Dave

0 new messages