Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in the code i am create a function to convert USA date time to "India Standard Time". when i am convert date Time, date is display correct but time always return 12:30 PM. can anybody help me ??

Code are given below

C#
public string getDateTime(string dat, string format)
       {
           string _ret = "";
           try
           {
               DateTime dt = Convert.ToDateTime(dat);
               string serverlocal = "Pacific Standard Time";// TimeZoneInfo.Local.Id;
               string clientLocal = Convert.ToString(HttpContext.Current.Session["TZ"]);
               _ret = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, serverlocal, clientLocal).ToString(format);
           }
           catch (Exception ex)
           {

           }
           return _ret;
       }



string dat = getDatetime("2014/07/14 19:35:00","hh:mm tt");

always return 12:30PM

On localhost run fine, but on server time always 12:30PM
application are hosted on USA server
Please help me
Posted
Comments
CHill60 14-Jul-14 6:57am    
It worked fine for me, but I had to change the line string clientLocal = Convert.ToString(HttpContext.Current.Session["TZ"]); ... worth checking what is in that session variable?

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