0

我在 C# 中有以下代码行:

DateTime dtReportDate = Convert.ToDateTime(_ReportDate);

_ReportDate 是一个字符串变量,其值为:21/05/2013 (dd/MM/yyyy)。所以我尝试将该日期转换为 DateTime 变量并执行以下操作:

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

如您所见,我需要以如下格式连接日期和小时:yyyy/MM/dd HH:mm。

在本地运行这些代码行时,它可以正常工作。但是,当我将它放在开发服务器中时,它会引发以下错误:String was not Recognized 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 回答