Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:29am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This class should do the trick according to the Microsoft documentation:
http://msdn.microsoft.com/en-us/library/bb382770.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 230
2 ClimerChinna 222
3 vikinghunter 178
4 OriginalGriff 161
0 Sergey Alexandrovich Kryukov 8,373
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100