我有这个字符串:
\tid <01CA4692.A44F1F3E@blah.blah.co.uk>; <b>Tue, 6 Oct 2009 15:38:16</b> +0100
我想将日期(加粗)提取为更有用的格式,例如2009 年 6 月 10 日 15:38:16
解决此问题的最佳方法是什么?
最佳答案
正则表达式可能有点矫枉过正。只需在 ';' 上拆分,Trim()
,然后调用 Date.Parse(...)
,
它甚至会为您处理时区偏移量。
using System;
namespace ConsoleImpersonate
{
class Program
{
static void Main(string[] args)
{
string str = "\tid 01CA4692.A44F1F3E@blah.blah.co.uk; Tue, 6 Oct 2009 15:38:16 +0100";
var trimmed = str.Split(';')[1].Trim();
var x = DateTime.Parse(trimmed);
}
}
}
关于c# - 如何从这个字符串中获取日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1532536/