将日期2012-09-13T05:08:03.151Z转换为本地时区 [英] Convert a date 2012-09-13T05:08:03.151Z to local timezone

查看:104
本文介绍了将日期2012-09-13T05:08:03.151Z转换为本地时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在使用C#将日期从以下格式转换为印度时区(UTC + 5:30)中的日期时遇到问题?

Hello guys,

I am facing a problem in converting a date from following format to a date in the India time zone (UTC+5:30) using C#?

2012-09-13T05:08:03.151Z



在此问题上的任何帮助将是可观的.请提供您的答案参考.

我已经尝试过的东西:



Any help in this matter would be appreciable. Please provide references for your answer.

Stuff that I have already tried :

DateTime.ParseExact("2012-09-13T05:08:03.151Z",
                                  "yyyy-MM-dd HH:mm:ssK",
                                  CultureInfo.InvariantCulture)





DateTime.ParseExact("2012-09-13T05:08:03.151Z",
                                  "yyyy-MM-ddThh:mm:ss.SSSZ"
                                  CultureInfo.InvariantCulture)</pre>



我在转换{System.FormatException}时遇到问题

在此先感谢



I am facing problem in conversion {System.FormatException}

Thanks in advance

推荐答案

此类应根据Microsoft文档进行操作:
http://msdn.microsoft.com/en-us/library/bb382770.aspx [ ^ ]
This class should do the trick according to the Microsoft documentation:
http://msdn.microsoft.com/en-us/library/bb382770.aspx[^]


string date = "2009-02-25 16:13:00Z"; // Coordinated Universal Time string fromDateTime.Now.ToUniversalTime().ToString("u"); 
DateTime localDateTime = DateTime.Parse(date); // Local .NET timeZone. 



参考文献:
http://stackoverflow.com/questions/179940/c- sharp-convert-utc-gmt-time-to-local-time [在UTC(全球协调时间)和本地时间之间进行转换 [ ^ ]



References:
http://stackoverflow.com/questions/179940/c-sharp-convert-utc-gmt-time-to-local-time[^]

For more information, look at the following link in CP:
Convert between UTC (Universal Co-ordinated Time) and local time[^]


string Date = "2009-02-25 16:13:00Z";
DateTime localDateTime = DateTime.Parse(Date); // Local .NET timeZone. 
DateTime utcDateTime = localDateTime.ToUniversalTime();

string nzTimeZoneKey = "New Zealand Standard Time"; 
TimeZoneInfo nzTimeZone = TimeZoneInfo.FindSystemTimeZoneById(nzTimeZoneKey); 
DateTime nzDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, nzTimeZone);

Console.WriteLine("Date : {0}", Date);
Console.WriteLine(" localDateTime: {0}", localDateTime);
Console.WriteLine(" nzTimeZone: {0}", nzTimeZone);
Console.WriteLine(" : {0}", nzDateTime);
Console.ReadLine();


这篇关于将日期2012-09-13T05:08:03.151Z转换为本地时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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