string strValue = "7 juli 2013";
// Convert to DateTime
CultureInfo dutch = new CultureInfo("nl-NL", false);
DateTime dt = DateTime.Parse(strValue, dutch);
// Convert the DateTime to a string
CultureInfo ci = new CultureInfo("en-US", false);
strValue = dt.ToString("d MMM yyyy", ci);
最初に文字列を に変換しDateTime
、次に . !ToString
_DateTime
そして、一般的に、Convert.ToDateTime
英語のみを使用するのは誤りです。Convert.ToDateTime(string, IFormatProvider)
あなたが使用したオーバーロードはあなたのPCの現在の文化を使用しています(私のPCではイタリア語を使用しています)CultureInfo
.
多言語... しかし、これは間違っていることに注意してください! ある単語が異なる場所で異なる意味を持っていないことを確認することはできません!!!
// The languages you want to recognize
var languages = new[] { "nl-NL", "it-IT" };
DateTime dt = DateTime.MinValue;
bool success = false;
foreach (var lang in languages)
{
if (DateTime.TryParse(strValue, new CultureInfo(lang, false), DateTimeStyles.AssumeLocal, out dt))
{
success = true;
break;
}
}
if (success)
{
CultureInfo ci = new CultureInfo("en-US", false);
strValue = dt.ToString("d MMM yyyy", ci);
}