Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(Here client means our client.Client side means the side of our client of this app,not the web programming server-client's client.)


We have an customer support web app in asp.net. Now, say our client is in UK.Then all the system will be operated in uk time zone irrespective of server time on which the pages are kept.

Let a service is set in 5pm uk time.Then when a support member search for that service,he will see the service is set on 5pm even if he is in India.Time will not be converted.

also the calender controls,which generally fetch user's datetime, have to be set so that it can show our clients time zone time and date.

Also I can not use server datetime, as the server may be in different timezone as of client.I can make a calculation to convert server time to our client time.But if client changes his server,then?I have to rewrite calculation.

In a sentence,full system,outputs and inputs whatever,those will be in clients time zone.At first we have to set clients time zone in my app before giving him this app,then all the app will work in his time zone.

So how to do it?Can anyone give any idea?Also you can tell any easy way if I'm thinking in wrong way.
Posted

Yes, and that is exactly where UTC timing jump in and saves you.

https://en.wikipedia.org/wiki/Coordinated_Universal_Time[^]

You can use this timing to save all of the processing times in the UTC time, and just Add Hours to the DateTime. This way, the timing on the server would be same, but the client would see the time in his locale time by adding (or subtracting) hours, minutes etc.

You can wonder it like, a post on Facebook was posted by me at 12:00 AM UTC, and it was shown to me at 5:00 AM PST, how? Because they just added 5 hours to the time that was saved, something like this

C#
// you can use variable in the place of 5
DateTime dateForClient = dateOnServer.AddHours(5);


I am having a working fiddle for you, where you can test this process. https://dotnetfiddle.net/KFBSDJ[^]

Good luck.
 
Share this answer
 
Comments
souvikcode 27-Oct-14 7:38am    
Thank you first. So,first I save +hour or -hour in database as per client.Then I'll do all operation in utc and when fetching record,I'll show utc+-hour.Right?If I write datetime.utcnow,it is fixed for all server,isn't it?Do you know how a machine fetch current utc time?
Afzaal Ahmad Zeeshan 29-Oct-14 10:44am    
In ASP.NET you can use this code to get the UTC time, DateTime.UtcNow. This will return the UTC time.
souvikcode 4-Nov-14 7:27am    
I know that.Actually I wanted to know that the utc time is fetched from internet or it is set in machine.As I can change my time,can I change utc time of my machine?
Afzaal Ahmad Zeeshan 4-Nov-14 7:32am    
No no, .NET runs on your Internet, it doesn't require any code to fetch the result from Internet, unless you're accessing a document online.
souvikcode 5-Nov-14 9:21am    
Can you tell,if I write datetime.utcnow for my asp application and save it to database,then from which machine my code take the utc date,from client machine or from server machine?
Datetime.now/utcnow function always fetch server date time,I'm right?
You could also simply track all time in UTC and use conversions on the client to display the date using local time (using javascript). If you are obtaining the date for something, the client can generate a utc date in javascript and pass it to the server.

The advantage of this approach is that it will work with any timezone.

This article has some discussion about it and should be a good start.

http://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript
 
Share this answer
 
Comments
souvikcode 27-Oct-14 7:35am    
Thanks

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