string类型组成DateTime类型

hgx54599 2010-01-20 03:54:44
如题 .. 例:我要把 091217 100226 转成 09-12-17 10:02:26
困扰好久 ...希望大家帮我下
...全文
85 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sportboy2008 2010-01-20
  • 打赏
  • 举报
回复
Visual Studio里debugger一下,多试几次就有了
hhc123 2010-01-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tchjl2007 的回复:]
Convert.ToDateTime("091217 100223").ToString("yyyy-MM-dd HH:mm:ss")
[/Quote]
DateTime dat = DateTime.Parse(s);s是个时间字符串
全部是错的
hgx54599 2010-01-20
  • 打赏
  • 举报
回复
....自己解决了 不过还是十分感谢大家 散分
Hamsic 2010-01-20
  • 打赏
  • 举报
回复
string strDate = "091217 100223";
strDate = strDate.Replace(" ","");
strDate = strDate.Trim().Substring(0, 2) + "-" + strDate.Trim().Substring(2, 2) + "-" + strDate.Trim().Substring(4, 2)
+ " " + strDate.Trim().Substring(6, 2) + ":" + strDate.Trim().Substring(8, 2) + ":" + strDate.Trim().Substring(10, 2);
大黄鸭在发光 2010-01-20
  • 打赏
  • 举报
回复
DateTime dat = new DateTime();
string h = "09-12-17 10:02:26";
dat = DateTime.Parse(h);
十八道胡同 2010-01-20
  • 打赏
  • 举报
回复
static DateTime StrToDateTime(string str)
{
Regex re=new Regex(@"\d{2}");
MatchCollection mc = re.Matches(str);
List<int> list = new List<int>();
foreach (Match m in mc)
list.Add(Convert.ToInt32(m.Value));
return new DateTime(list[0], list[1], list[2], list[3], list[4], list[5]);
}


 DateTime dt = StrToDateTime("091217 100226 ");
Console.WriteLine(dt.ToString("yy-MM-dd hh-mm-ss"));
大黄鸭在发光 2010-01-20
  • 打赏
  • 举报
回复
DateTime dat = DateTime.Parse(s);s是个时间字符串
Hamsic 2010-01-20
  • 打赏
  • 举报
回复
Convert.ToDateTime("091217 100223").ToString("yyyy-MM-dd HH:mm:ss")

111,120

社区成员

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

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

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