0

C# に次のコード行があります。

DateTime dtReportDate = Convert.ToDateTime(_ReportDate);

_ReportDate は文字列変数で、その値は 2013 年 5 月 21 日 (dd/MM/yyyy) です。だから私はその日付を DateTime 変数に変換しようとし、次のことを行います:

_ReportDate = string.Format("{0:yyyy/MM/dd}", dtReportDate) + " " + _ReportHour;

ご覧のとおり、日付と時間を yyyy/MM/dd HH:mm の形式で連結する必要があります。

これらのコード行をローカルで実行すると、問題なく動作します。しかし、開発サーバーに配置すると、次のエラーがスローされます: String was not registered as a valid DateTime

そこで、いくつか質問をしたいと思います。このエラーは、サーバーの構成に関連している可能性がありますか? Convert.ToDateTime がローカルでは正常に動作するのに、サーバーでは動作しないのはなぜですか?

どんな手がかりでも大丈夫です

ありがとう

4

1 に答える 1

0

I have figure out how to solve this problem executing the following line of code:

//Attempts to Parse the Date using the format specified (the third parameter can also be null)
DateTime dtReportDate = DateTime.ParseExact(_ReportDate,"dd/MM/yyyy", CultureInfo.InvariantCulture);

Hope this help others

于 2013-05-24T21:33:38.570 に答える