如何在C#中将Datetime转换为ISO 8601 [英] How to convert Datetime to ISO 8601 in C#

查看:149
本文介绍了如何在C#中将Datetime转换为ISO 8601的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将12/16/2015 11:52:09 AM转换为C#asp .net中的ISO 8601格式并生成DateTime。



例如:
DateTime dt = 2015年12月16日11:52 :09:00;转换后的

new

DateTime dt2 = YYYY-MM-DDThh:mm:ss或DateTime dt2 = 2015-12-17T03:40:56

解决方案

嗨Shaprpuff,



为此,请在日期时间对象上使用.ToString方法和自定义字符串格式。



这两个链接向您展示如何操作:

DateTime .ToString方法(字符串) [ ^ ]

自定义日期和时间格式字符串 [ ^ ]



实际上,您不需要转换它,只需要正确格式化。

How can I convert "12/16/2015 11:52:09 AM" to ISO 8601 format in C# asp .net and result in DateTime.

Exmple: 
 DateTime dt="12/16/2015 11:52:09 AM";

after converting dt new 

DateTime dt2="YYYY-MM-DDThh:mm:ss" or DateTime dt2="2015-12-17T03:40:56"

解决方案

Hi Shaprpuff,

To do this use the .ToString method on your date time object and a custom string format.

These two links show you exactly how to do it:
DateTime.ToString Method (String)[^]
Custom Date and Time Format Strings[^]

Effectively, you don't need to convert it, you just need to format it correctly.


这篇关于如何在C#中将Datetime转换为ISO 8601的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆