この問題に関する投稿が多数あることは知っていますが、どれもうまくいかなかったので、自分で投稿することにしました。スパムでないことを願っています。
私がやりたいことは、文字列を DateTime オブジェクトに変換することだけです。VS Web 開発サーバーでは問題なく動作しましたが、IIS に発行すると、「文字列は有効な DateTime として認識されませんでした」という例外がスローされ始めました。私は数多くの投稿を見て、次のコードを試しましたが、すべて失敗しました。簡単にするために、DateTime 文字列をハード コーディングしました。文字列の DateTime の形式は固定されていることに注意してください。それのみを使用する必要があります。
Convert.ToDateTime("27-6-2012 9:05 PM")
// Just for the sake of it I also used CurrentUICulture and InstalledUICulture in the line below.
// Note: For me CurrentCulture = CurrentUICulture = InstalledUICulture = en-US
Convert.ToDateTime("27-6-2012 9:05 PM", CultureInfo.CurrentCulture)
DateTime.Parse("27-6-2012 9:05 PM")
// Just for the sake of it I also used CurrentUICulture and InstalledUICulture in the line below.
// Note: For me CurrentCulture = CurrentUICulture = InstalledUICulture = en-US
DateTime.Parse("27-6-2012 9:05 PM", CultureInfo.CurrentCulture)
// Just for the sake of it I also used CurrentUICulture and InstalledUICulture in the line below.
// Note: For me CurrentCulture = CurrentUICulture = InstalledUICulture = en-US
DateTime.ParseExact("27-6-2012 9:05 PM", "{0:d-M-yyyy h:mm tt}", CultureInfo.CurrentCulture)
次に、実験のために、文字列の日付の形式を「6/27/2012 9:05 PM」に変更しました。DateTime.ParseExact を除いて、上記のすべてが機能することがわかりました。上記のコードのいずれかが機能する場合、私は問題ありませんが、問題は、文字列の日付の形式を変更できないことです。これは、制御できないパラメーターとして提供されます。
これは些細な問題のように見えますが、何が欠けているのかわかりません。とても恥ずかしいです。誰でも私を助けてもらえますか?
前もって感謝します。