Timezone problems in rails3
In my rails application,After login a user has to cre开发者_C百科ate a timesheet entry.The time of creation of the entry is currently my server time.Whereas i want it to be the time of the timezone from where the entry is made i.e if entry is made from any other country.I'm using rails 3 and after searching the web also exact solution cannot be achieved.
Thanx
You can't automatically determine the user's timezone, but you can allow them to choose their own timezone. Then you can set Time.zone = ActiveSupport::TimeZone(offset)
before calling update and everything should work correctly. You could also save each user's preference for time zone in your user model.
I'm not sure if it's possible to do this in Rails as the issue is getting the physical location of a user.
It may be worth using JavaScript to populate a (hidden?) field with the current time, which should be taken from user's local machine. You could then explicitly set the created_at field to be this value.
Intrigued to know if Rails can get around this somehow...
If you want, take a look to this question : transform time into local time in Ruby on Rails
And : http://www.wetware.co.nz/blog/2009/07/rails-date-formats-strftime/
Maybe it can helps you.
精彩评论