本文介绍了DateTime的字符串转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们, 我的字符串值为第9周(或)当前周:2013年2月24日 - 2013年3月2日 但我想将startdate作为2/24/2013并将EndDate作为3/2/2013进入DATETIME。 我怎么能转换它。请帮助我。
解决方案你可以使用Convert.ToDateTime()或ThePhantomUpvoter提到的其他方法。
试试这个使用正则表达式的示例代码.. 字符串输入=第9周(或)当前周:2013年2月24日 - 2013年3月2日; MatchCollection matches = Regex.Matches(input,@\d {1,2} / \d {1,2} / \d {4}); DateTime dt = DateTime.Parse(匹配[0] .Value); DateTime dt2 = DateTime.Parse(匹配[1] .Value);
也通过以下链接 正则表达式 - 字符串后跟日期 [ ^ ]
使用 DateTime.Parse( 2013年2月24日);
Hi Friends, I have string value is "Week 9 (or) Current week: 2/24/2013 - 3/2/2013" But I want startdate as "2/24/2013" and EndDate as "3/2/2013" into DATETIME. How can i convert it. Please help me.
解决方案 You can use Convert.ToDateTime() or the other methods mentioned by ThePhantomUpvoter.try this exampal code using regex.. string input = "Week 9 (or) Current week: 2/24/2013 - 3/2/2013"; MatchCollection matches = Regex.Matches(input, @"\d{1,2}/\d{1,2}/\d{4}"); DateTime dt =DateTime.Parse(matches[0].Value); DateTime dt2 = DateTime.Parse(matches[1].Value);also go through following link Regular expression - String followed by a date[^]
Use DateTime.Parse("2/24/2013");更多推荐
DateTime的字符串转换
发布评论