如何在C#中将带有'T'的日期转换为字符串 [英] how to convert date with 'T' to/from string in C#
本文介绍了如何在C#中将带有'T'的日期转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下函数将 DateTime
从/转换为 string
:
DATE_OBJ.ToString(DATE_FORMAT);
DateTime.ParseExact(Date_string,DATE_FORMAT,null);
现在我要使用以下格式 2012-03-20T14 :18:25.000 + 04:00
我应使用哪种格式将其正确转换为 string
并从 DateTime
对象生成 string
一样?
解决方案
您可以使用
DateTime dt =从DateTime转换为该格式。新的DateTime();
dt.ToString( o);
,然后使用
<$从该格式转换为DateTime p $ p>
DateTimeOffset.Parse(dateString);
以下是有关DateTime格式的更多信息:
http://www.dotnetperls.com/datetime-format
I used following functions to convert DateTime
from/into string
:
DATE_OBJ.ToString(DATE_FORMAT);
DateTime.ParseExact(Date_string, DATE_FORMAT, null);
Now I've got to work with follow format 2012-03-20T14:18:25.000+04:00
Which format should I use to convert it correctly to string
and generate string
like that from DateTime
object?
解决方案
You can go from DateTime to that format with
DateTime dt = new DateTime();
dt.ToString("o");
and from that format to DateTime with
DateTimeOffset.Parse(dateString);
Here is some more info on DateTime format: http://www.dotnetperls.com/datetime-format
这篇关于如何在C#中将带有'T'的日期转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文