如何将string转成DateTime对相高分请教

极限999 2003-10-22 09:39:50
从数据库存读出来的字符串如"2003-4-5 4:45:10"
怎么样才可以DateTime dt=new DateTime();
dt中所存的时间为上面的字符串呢,在线等侍,答对马上给分
...全文
57 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
极限999 2003-10-22
  • 打赏
  • 举报
回复
谢谢各位一会就结账
lbywyj 2003-10-22
  • 打赏
  • 举报
回复
当你把2003-4-5 4:45:10变成string的话,
DateTime dt = DateTime.Parse("2003-4-5 4:45:10"); 最简练;
如果只取其中的“2003-4-5”或者“4:45:10”那么分别用
DateTime dt=Convert.ToDateTime(str).ToShortDateString

DateTime dt=Convert.ToDateTime(str).ToShortTimeString
liupeng1981 2003-10-22
  • 打赏
  • 举报
回复
DateTime.Parse(string)
liuhealth 2003-10-22
  • 打赏
  • 举报
回复
直接Convert.ToDateTime(string)就可以了
csdn_bob 2003-10-22
  • 打赏
  • 举报
回复
DateTime dt = DateTime.Parse("2003-4-5 4:45:10");
minajo21 2003-10-22
  • 打赏
  • 举报
回复

dt=Convert.ToDateTime(Convert.ToDateTime(strTemp).ToShortDateString + " " + Convert.ToDateTime(strTemp).ToShortTimeString)
minajo21 2003-10-22
  • 打赏
  • 举报
回复
dt=Convert.ToString(Convert.ToDateTime(strTemp).ToShortDateString + " " + Convert.ToDateTime(strTemp).ToShortTimeString)

111,125

社区成员

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

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

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