如何判断"2008-10-10 10:45:00"里面存在空格!

meteormeng 2008-07-16 03:24:51
strTime = dsexcel.Tables[0].Rows[i]["TIME"].ToString(); //strTime = "1899-12-30 10:45:00"
(dsexcel.Tables[0].Rows[i]["TIME"].ToString().Split(' '))[1].Contains(":")/*当strTime = "10:45:00"时,这条语句越界了,故我需要判断strTime 是否有空格*/
不知如何写,请赐教!
...全文
112 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
meteormeng 2008-07-17
  • 打赏
  • 举报
回复
哈哈,是这样写就对了,strTime = DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"].ToString()).ToString("hh:mm:ss");
多谢楼上的兄弟们!
meteormeng 2008-07-17
  • 打赏
  • 举报
回复
写清楚点:
Error 3 The best overloaded method match for 'System.DateTime.Parse(string)' has some invalid arguments
Error 4 Argument '1': cannot convert from 'object' to 'string'
meteormeng 2008-07-17
  • 打赏
  • 举报
回复
我用:
strTime = (DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"])).ToString("hh:mm:ss");//之后出现以下报错!
Error 3 The best overloaded method match for 'System.DateTime.Parse(string)' has some invalid arguments F:\work_file\ExcelToXmlConverter\ExcelToXmlConverter\JobExporter.cs 1082 28 MC2JobExporter
Error 4 Argument '1': cannot convert from 'object' to 'string' F:\work_file\ExcelToXmlConverter\ExcelToXmlConverter\JobExporter.cs 1082 43 MC2JobExporter
conan304 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 whycom 的回复:]
strTime = DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"]).ToString("hh:mm:ss")
[/Quote]
strTime = DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"]).ToString("HH:mm:ss");
aaajedll 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 whycom 的回复:]
strTime = DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"]).ToString("hh:mm:ss")
[/Quote]
whycom 2008-07-16
  • 打赏
  • 举报
回复
strTime = (DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"])).ToString("hh:mm:ss")
whycom 2008-07-16
  • 打赏
  • 举报
回复
strTime = DateTime.Parse(dsexcel.Tables[0].Rows[i]["TIME"]).ToString("hh:mm:ss")
ASCRIBE 2008-07-16
  • 打赏
  • 举报
回复
string temp="1899-12-30 10:45:00"

if(temp.indexof(" ")==-1)

// 不包含 空格
else
//包含 空格
meteormeng 2008-07-16
  • 打赏
  • 举报
回复
这个日期是从excel表格中取出来的,所以不能直接操作,要一段段的处理:
string strTime;
strTime = dsexcel.Tables[0].Rows[i]["TIME"].ToString(); //strTime = "1899-12-30 10:45:00"

if ((dsexcel.Tables[0].Rows[i]["TIME"].ToString().Split(' '))[1].Contains(":")) // strTime "03:00:00" string
{
strTime = (dsexcel.Tables[0].Rows[i]["TIME"].ToString().Split(' '))[1]; //strTime = "10:30:00"
}
else
{
string tempstrtime = dsexcel.Tables[0].Rows[i]["TIME"].ToString(); //tempstrtime = "10:30:00 上午"
strTime = (tempstrtime.Substring(0, tempstrtime.IndexOf(' ') + 1)); //strTime = "10:30:00 "
}

string strDate = (dsexcel.Tables[0].Rows[i]["DATE"].ToString().Split(' '))[0]; //strDate = "2008-6-28"
strTempJobTitle = dsexcel.Tables[0].Rows[i]["PROGRAM"].ToString(); //strTempJobTitle = "LATE SHOW"
if (strTempJobTitle == "")
{
continue;
}

strTempChannel = tempchannel.ToString(); //strTempChannel = "2"

DateTime myDateTime = DateTime.Parse(strDate + " " + strTime, new CultureInfo("en-US", true), DateTimeStyles.NoCurrentDateDefault); //myDateTime = {2008-6-28 10:30:00}
strTempDate = String.Format("{0:yyyy}-{0:MM}-{0:dd}", myDateTime) + " " + String.Format("{0:HH}:{0:mm}:{0:ss}", myDateTime); //strTempDate = "2008-06-28 10:30:00"
freewind0521 2008-07-16
  • 打赏
  • 举报
回复
if (strTime.Contains(" ") || strTime.Contains(" ") )
{

}
lovefootball 2008-07-16
  • 打赏
  • 举报
回复
IndexOf(" ")>=0

不知道你想干什么
为什么不把它Convert.ToDateTime后直接操作日期???

110,825

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧