如何在C#中转换dateformat [英] How to convert dateformat in C#

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

问题描述

你能帮我解决一下如何转换如下的日期时间格式



Could you please help me that how to convert datetime format like below

2017-04-26T12:30:16+08:00





我想准确传递上述日期时间格式



< b>我尝试了什么:



我尝试使用以下代码但没有使用+



I want to pass the above datetime format exactly

What I have tried:

I have tried with the below code but not getting with +

2017-04-26T12:30:16+08:00







DateTime dt = new DateTime();
            dt = DateTime.Now;
 Label13.Text = String.Format("{0:s}", dt);







2017-04-26T12:30:16

推荐答案

试试这个:

Try this:
DateTime d = new DateTime(2017, 6, 7, 13, 14, 15, DateTimeKind.Utc);
string s = d.ToLocalTime().ToString("yyyy-MM-dd HH:mm:sszzz");
Console.WriteLine(s);



它产生了这个:


It produces this:

2017-06-07 14:14:15+01:00

因为我在英国时间 - 目前是BST,比UTC早一个小时。

because I'm on UK time - currently BST, one hour ahead of UTC.


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

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