1

I have a dateTime field with the format dd/MMM/yyyy (05/NOV/2013). I want to change the "NOV" in some other language (e.g: Arabic). How can I convert it?

Edit: Sorry for not providing the code, here it is.

C# Code:

string tempGrgDt = Convert.ToString(DateTime.Now.ToString("dd/MMM/yyyy"));
AbdulAziz
  • 5,868
  • 14
  • 56
  • 77
  • 3
    It's unclear what you mean. `DateTime` itself doesn't have a format - you format it however you want to. It would be really helpful if you could provide code... – Jon Skeet Nov 05 '13 at 18:47
  • 1
    Do you mean you want something like this? http://stackoverflow.com/a/9022326/2258 – Richard Morgan Nov 05 '13 at 18:51

1 Answers1

9

You just need this

var date = DateTime.Now.ToString("dd/MMM/yyyy",new CultureInfo("ar"));

Prints

02/محرم/1435

You need to pass the CultureInfo while converting DateTime to String. You'll get localized string in the given culture.

Update: If you have three letter month in english and you need to convert to arabic month you can do this

var dt = DateTime.ParseExact("NOV", "MMM", CultureInfo.InvariantCulture);
string arabicMonth = new CultureInfo("ar").DateTimeFormat.GetMonthName(dt.Month);
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
  • Thanks for the answer, but this was not my exact answer to my question. I didn't asked for the localize of whole date. I want just to replace NOV by some Arabic text like يناير – AbdulAziz Nov 05 '13 at 19:01
  • Then change the formatting string from "dd/MMM/yyyy" to whatever suits your fancy. That is the correct Arabic, right? – Robert Harvey Nov 05 '13 at 19:02
  • Yes, but it changes the whole Gregorian date to Hijri date. I am asking that is there a way to edit the text of NOV in dd/MMM/yyyy to some text? – AbdulAziz Nov 05 '13 at 19:03
  • This answer will give you what you want, not sure what the problem is? – Sven Grosen Nov 05 '13 at 19:07