C# DateTime.ParseExact无法在c中正确分析日期#
我有一个yyyy-MM-dd hh:MM:ss tt格式的字符串日期,我想将其转换为具有相同格式的日期时间 下面是c#中的代码 GetNextValidDate返回一个字符串“2016-03-23 01:00:00 PM”,我想将其转换为具有相同格式的日期时间C# DateTime.ParseExact无法在c中正确分析日期#,c#,date,datetime,C#,Date,Datetime,我有一个yyyy-MM-dd hh:MM:ss tt格式的字符串日期,我想将其转换为具有相同格式的日期时间 下面是c#中的代码 GetNextValidDate返回一个字符串“2016-03-23 01:00:00 PM”,我想将其转换为具有相同格式的日期时间 如何做到这一点?在渲染到日期时,请尝试以下方法: foreach(DateTime d in dates) { string DateString = d.ToString("yyyy-MM-dd hh:mm:ss");
如何做到这一点?在渲染到日期时,请尝试以下方法:
foreach(DateTime d in dates)
{
string DateString = d.ToString("yyyy-MM-dd hh:mm:ss");
//Do something with the string called, DateString
}
“不工作”怎么说?您是否收到异常?否它返回的日期格式错误。我认为您将调试器显示的值与实际存储的值混淆了。在内部,
DateTime
只是一个数字。您可以使用多种不同的方式对其进行格式化。为了方便起见,调试器恰好以某种方式显示它。如果要格式化它,请使用适当的ToString()
参数将其输出为字符串。不应该GetNextValidDate
返回DateTime
?DateTime
没有特定的格式
foreach(DateTime d in dates)
{
string DateString = d.ToString("yyyy-MM-dd hh:mm:ss");
//Do something with the string called, DateString
}