Once UI's culture is set, you shouldn't have to worry about it, period -- unless you're already doing some other explicit form of parsing.
At that point, if you simply display a UTC date, it should display in the user's local time ... I've never had to explicitly parse with a culture's specific formatter. Then again, it's been 4-5 years since I've worked with ASP.NET localization. ∞ Andy Badera ∞ +1 518-641-1280 ∞ This email is: [ ] bloggable [x] ask first [ ] private ∞ Google me: http://www.google.com/search?q=andrew%20badera On Thu, Sep 17, 2009 at 5:17 AM, Jay Dan <[email protected]> wrote: > Thank you for the quick re[ply I really appreciate. > > > > Comment 1: Yes, you guessed it right I am not using dynamic sql it’s just > for the demonstration and it is quick J. > > > > Comment 2: It is getting handled automatically (date format) but the date > and times are not depending upon the user’s time zones! > > > > I have found a hint here > http://msdn.microsoft.com/en-us/library/bb882561.aspx. > > On Thu, Sep 17, 2009 at 2:31 PM, Andrew Badera <[email protected]> wrote: >> >> HINT: DO NOT USE DYNAMIC SQL. PERIOD. JESUS CHRIST IS IT 2009 OR 1999 >> HERE? SQL INJECTION FRIGGIN' CITY. >> >> I know that a) that's not what you asked and b) may not even apply >> directly to the code in question, but if you're using dynamic SQL at >> all, anwhere, in the least bit, it means you're using it too much. >> >> More relevant hint: when CurrentCulture is autodetected, or set, you >> shouldn't have to manually convert dates. They UI thread should handle >> formats and timezones for you. >> >> Another relevant hint: let autodetection work for you! User's browsers >> should indicate language and timezone to the server automagically, you >> shouldn't have to determine that manually the way you're doing. >> >> ∞ Andy Badera >> ∞ +1 518-641-1280 >> ∞ This email is: [ ] bloggable [x] ask first [ ] private >> ∞ Google me: http://www.google.com/search?q=andrew%20badera >> >> >> >> On Thu, Sep 17, 2009 at 4:56 AM, Jay <[email protected]> wrote: >> > >> > Hello All, >> > >> > I have a requirement let me know if it is possible. There will be a >> > web application which will be accessed by users from different >> > countries. No matter where the user is accessing from I will be saving >> > the dates in utc format as an example >> > >> > strSQL = "Insert into emp(joindate)values >> > ('"+DateTime.Now.ToUniversalTime()+"');"; >> > Now at the time of retrieving the dates I have to show the dates >> > depending on the timezone of the user accessing the web page. >> > For that I have used the following code segment >> > >> > Response.Write(Convert.ToDateTime(reader["joindate"].ToString >> > (),Thread.CurrentThread.CurrentCulture.DateTimeFormat) + "<br>"); >> > >> > Following is the code segment which I have have used in the >> > Global.asax.cs Application_BeginRequest to retrieve the first language >> > from browser language list. >> > >> > HttpRequest request = HttpContext.Current.Request; >> > if (request.UserLanguages == null) return; >> > string language = request.UserLanguages[0]; >> > if (language != null) >> > { >> > if (language.Length < 3) >> > { >> > language = language + "-" + language.ToUpper(); >> > } >> > Thread.CurrentThread.CurrentUICulture = new CultureInfo >> > (language); >> > Thread.CurrentThread.CurrentCulture = new CultureInfo >> > (language); >> > } >> > I have added new language from languages add option (internet >> > explorer) for example French (France) [fr-FR]. Now when the date is >> > rendering it is formatted with the code page, but is there any way to >> > automatically increment /decrement the date time detecting the >> > timezone the user is accessing the web page? One way it could be done >> > I can explicitly mention the time zone and add / subtract the time >> > difference. >> > >> > Please let me know if you have any hint. >> > > > > > -- > Jay >
