Chirag Kavathiya
Chirag Kavathiya

Reputation: 24

How to handle Globally time_zone in system?

I am working on module called Activity, User can do any activity from any country like you comment on Facebook or other social-media site. Whenever comment happen every user globally see that comment happen just now.

Problem: I have WCF API that will store the data in UTC time format. The API can be accessible from IPad, IPhone and other device. I have to give response in day-wise activity count. The user will be in different timezone, hence the activity count will be differ from different time-zone. like CST time is -06:00 offset and IST time +05:300 offset. how to find the count from the server based on the different time-zone. Whenever they call for retrieving data from server they don't specification any time-zone. how to handle this kind off situation.

Is it make any different to use datetimeOffset. Can datetimeOffset be parse to JSON?

Thanks Chirag.

Upvotes: 0

Views: 52

Answers (2)

Martin Liversage
Martin Liversage

Reputation: 106826

  1. You can convert the UTC time to local time on the server. This requires that the client includes it's local time zone in the request. This will allow the server to send back timestamps that are in the local time zone of the client.

    The DateTimeOffset class helps with that on the server side. The DateTime class can only represent UTC and "local" time as in the the local time of the server. DateTimeOffset allows you to represent time with any offset but the time zone is part of the information. Time zone defines rules like daylight savings which is not part of the information stored in DateTimeOffset.

  2. Or you can convert the UTC time to local time on the client. Timestamps in server responses are always in UTC but the the client knows it's own time zone and performs the conversion before the timestamp is displayed.

In most cases I would think that 2. is the simplest solution but this requires that the client has information about time zones and that information is quite complicated.

Upvotes: 1

tobs4u
tobs4u

Reputation: 11

i use in my system the ISO 8601 to save the Time. There you will have the time zone information included.

https://en.wikipedia.org/wiki/ISO_8601

In .net it is the "o" or "o". https://msdn.microsoft.com/en-us//library/az4se3k1(v=vs.110).aspx

Also DateTimeOffset is supported.

Upvotes: 1

Related Questions