Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application running in server.User using this are from different time zone.Now I have to save the time of their inserted data.

When user save the data in database I am doing datetime.utcNow().I think it converts the local time of server(in which my application is situated) to utc time. Am I right?

Now I have saved all users' time zone on creating there account.Now I am showing their time of saved data (which is in database in utc) by converting from utc to their local time zone (from his account I'm fetching his time zone).

Am I in right way?please help,actually if I am in right way then I'll apply this approach to the whole project.
Posted
Comments
George Jonsson 20-Sep-14 9:03am    
You seem to have an idea of what you want to do.
Why not do a test implementation and try it out.
That's how you learn.

1 solution

If you are using the server time zone as the "Base" for your conversion to UTC and this is a web-based product, then no, it's not right. You need to use the user time zone, and correct for that - he may well be in a different time zone from your server (I am: I live in the UK, and my website server is in the USA).
This should help: http://msdn.microsoft.com/en-us/library/bb882561(v=vs.110).aspx[^] - it discusses a couple of approaches to the problem.
 
Share this answer
 
Comments
souvikcode 22-Sep-14 6:45am    
But if I convert all time to utc and save it to database and retrieve that time by converting utc to user time zone then where will be problem?I know the user time zone as they have account in my site.Let it is 4.13 pm in india and 12.43 pm in S.A.My server is in S.A.So if I convert the time to utc it will be saved as 10.44 am.So in that case I don't have to know where the user is.Am I right?

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