0

I'm trying to convert a date in format UTC "yyyy-MM-ddTHH:mmZ" to a localdatetime but when changing cultureInfo by fr-FR or other one, o keep always the same localdatetime

for example i do this:

IFormatProvider culture = new System.Globalization.CultureInfo("en-US",null);
DateTime tempDte= DateTime.MinValue;
string test = ""2014-04-09T14:29Z";
DateTime.TryParseExact(test , "yyyy-MM-ddTHH:mmZ", culture,    DateTimeStyles.AssumeLocal, out tempDte)

Console.WriteLine("col = " + s + " &init " + test  + " &ToLocalTime = " + tempDte.ToLocalTime() + " &ToUniversalTime = " + tempDte.ToUniversalTime());

Could you explain me how do this for having time depending on th eculture

Thanks

user1898765
  • 323
  • 1
  • 6
  • 18
  • [`cult`](http://www.merriam-webster.com/dictionary/cult) has nothing to do with `culture` - please make sure to use reasonable names AND make sure you don't have 2 similar variables in same scope. – Alexei Levenkov Apr 09 '14 at 17:20
  • i've corrected the code but still have the same localdatetime by changing us or fr – user1898765 Apr 09 '14 at 17:49
  • Can you please show an example of what you actually expect? I suspect you want France *timezone*, not FR-FR *culture*. If you are in Australia and ask some French speaking person "what time it is now" it will not make midnight into afternoon... – Alexei Levenkov Apr 09 '14 at 18:06
  • I've the test date and i'd like display the time in france and united states or some other regions – user1898765 Apr 09 '14 at 18:36
  • Please edit your question to actually explain that - `CultureInfo` has nothing to do with timezones, you are looking for [TimeZoneInfo](http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx class.. Now it is clear what this question is duplicate of. – Alexei Levenkov Apr 09 '14 at 18:50
  • possible duplicate of [Creating a DateTime in a specific Time Zone in c# fx 3.5](http://stackoverflow.com/questions/246498/creating-a-datetime-in-a-specific-time-zone-in-c-sharp-fx-3-5) – Alexei Levenkov Apr 09 '14 at 18:51
  • so if i understand well, cultureinfo is only for format date? – user1898765 Apr 09 '14 at 19:21
  • Yes. `CultureInfo` is for formatting/parsing of all data types including `DateTime`. – Alexei Levenkov Apr 09 '14 at 19:30

1 Answers1

0

You don't have seconds part in your DateTime String

Try This:

DateTime.TryParseExact(test , "yyyy-MM-ddTHH:mmZ", culture,    
                               DateTimeStyles.AssumeLocal, out validDate);

Note : Make sure you are printing the converted DateTime variable validDate

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • i've changed without second but doesn't still work and it would be tempDte in place of validDate. Should i have 2 localtime different if i use fr-FR or en-US? – user1898765 Apr 09 '14 at 17:47