Click here to Skip to main content
Sign Up to vote bad
good
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>
 
I am facing problem in conversion {System.FormatException}
 
Thanks in advance
Posted 13 Sep '12 - 3:29


3 solutions

This class should do the trick according to the Microsoft documentation:
http://msdn.microsoft.com/en-us/library/bb382770.aspx[^]
  Permalink  
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[^]
  Permalink  
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();
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Aarti Meswania 210
4 Maciej Los 200
0 Sergey Alexandrovich Kryukov 8,953
1 OriginalGriff 7,134
2 CPallini 3,758
3 Rohan Leuva 3,036
4 Maciej Los 2,488


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid