Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

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


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


I am facing problem in conversion {System.FormatException}

Thanks in advance
Posted

This class should do the trick according to the Microsoft documentation:
http://msdn.microsoft.com/en-us/library/bb382770.aspx[^]
 
Share this answer
 
C#
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. 


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[^]
 
Share this answer
 
v2
C#
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900