如何从给定的字符串中获取日期 [英] How to get the date from given string
本文介绍了如何从给定的字符串中获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从C#中获取给定字符串的日期
这里是我的代码
string dateString =20091229T213000;
字符串可由用户输入。如何以下面提到的格式从普通字符串中提取日期。
输出所需的输出是dd-MMM-yyyy
先谢谢
How to get the date from given string in C#
here is my code
string dateString = "20091229T213000";
string may enter by users. how to extract the date from the plain string in below mentioned format.
output required is in dd-MMM-yyyy
Thanks in Advance
推荐答案
使用 DateTime.ParseExact [ ^ ]为此...
Use DateTime.ParseExact[^] for that...
DateTime.ParseExact("20091229T213000", "yyyyMMddTHHmmss", CultureInfo.InvariantCulture);
请尝试以下代码
Please try the below code
string dateString = "20091229T213000";
dateString = DateTime.ParseExact(dateString, "yyyyMMddTHHmmss", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-yyyy");
使用
DateTime.TryParse
这篇关于如何从给定的字符串中获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文