views:

146

answers:

2

Hello,

How to convert DateTime.Now (or basically any other DateTime format) to something like 31st January 2009 (although i would like it in polish so i need 29 Styczeń 2009). Do i need to create some array and check each month number with that array or there's some built in feature to save the day?

With regards,

MadBoy

A: 

I'd format it using a DateTimeFormat with a Culture or Locale variable. The Date abstraction is independent of the way you render it.

duffymo
+6  A: 
CultureInfo polish = new CultureInfo("pl-PL");  // I *think* this is Polish -- you might need to check!
DateTime.Now.ToString("d MMMM yyyy", polish);

The CultureInfo already knows about month names in different locales -- if you need this info explicitly, e.g. to print out a list of month names, you can get it from the DateTimeFormatInfo class, but for a simple formatting requirement it's easier just to use DateTime.ToString with the required culture and a format string.

itowlson
That partially works. But can i make it show whole month? Right now it only shows 3 letters? I used varDo.ToString("d MMMMMMMMMMMMMM yyyy", polish) and it seems to work but is it the proper way?
MadBoy
Use 4 Ms. Produces "stycznia" which seem more correct then "Styczeń".
Hans Passant
Yes it's using correct grammar :-)
MadBoy
nobugz: fixed -- thanks!
itowlson