Click here to Skip to main content
15,913,349 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A student class has a property called birthday,my web Server is in BeiJing(UTC+8),When I get data from the server with json formate,the birthday always reduce 8 hours,How to correct my codes?Now I also in Beijing and I make all birthday to add 8 hours,but if I am in other timezone or the web server is not in beijing,I have to change to add other hours manually.
In web server,My Codes is:
C#
return Json(student);

The codes get the data is:
C#
var studentReader= new StreamReader(Request.InputStream);
var student= JsonHelper.FromJson<Student>(studentReader.ReadToEnd());

the JsonHelper class is :
C#
public static T FromJson<T>(this string json)
 {
  return JsonConvert.DeserializeObject<T>(json);
 }
Posted
Updated 25-May-13 22:22pm
v3
Comments
Jameel VM 26-May-13 14:20pm    
Convert the Date in to UTC date before return to JSON
PEIYANGXINQU 27-May-13 12:16pm    
Can you show me how to convert the Date in to UTC date before return to JSON? Now I read the birhday from database directly and return to JSON.I check my database,the birthday value like '2013-05-28 00:31:00.000',it seems not like the utc format.If my server time is not utc format, I want to change to time rely on clinet web brower,is it OK?For example,the server is in Beijing(utc+8),If I in utc+8 timezone,I get the data and add 8 hours,If I in utc+7 timezone,I get the data and add 7 hours.And another question,If the web server is in Utc+9 timezone like Tokyo,and I am in utc+7 timezone,am I also add 7 hours or 9 hours?As far as I know ,my database's birthday is not utc format and my web server is in Beijing(utc+8),and I am also in Beijing, ervery time I add the birthday from the server Json,I add the timezone(means 8 hours) manually,it runs well!

1 solution

you can do one thing try to convert the field "Birthdate" from datetime to string and then convert it into json format.
 
Share this answer
 

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