1

Web application is hosted on a server with (UTC+10.00)Canberra,Sydney,Melbourne TimeZone. When a user from Melbourne creates an event it saves the datetime to database in GMT format.

if the user selection is 23/12/2015 3:30:00 AM value saved to the DB will be 2015-12-22 16:30:00.000

Now when a user from (UTC+10.00)Brisbane visits the application it's still shows the same datetime but they are one hour behind from Melbourne time. So they are suppose to view

23/12/2015 2:30:00 AM

There could be users from different parts of Australia. How to convert this datetime to logged in users TimeZone?

chamara
  • 12,649
  • 32
  • 134
  • 210

2 Answers2

1

Check this.

TimeZone.CurrentTimeZone.ToLocalTime(date);

https://msdn.microsoft.com/en-in/library/system.datetime.touniversaltime(v=vs.110).aspx

Convert UTC/GMT time to local time

Community
  • 1
  • 1
Sudhir Panda
  • 774
  • 1
  • 7
  • 27
0

You can get the timezone offset from the clients browser using Javascript.

function returnTimeDiff(postDateTime, spanid) {
    var offset =(new Date().getTimezoneOffset() / 60)
}

Convert UTC time to Client browser's timezone using JavaScript in a MVC View

Community
  • 1
  • 1
Shep
  • 638
  • 3
  • 15