DateTime的字符串转换

编程入门 行业动态 更新时间:2024-10-27 11:15:27
本文介绍了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的字符串转换

本文发布于:2023-11-22 15:23:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!