0

I am developing Rails-4 application where I created 1 form for users.

Users from all over around the world. Now, I have to get timezone also of users which fill form without enter or select timezone.

I already used javascript cookies method and its work perfect like below code:

function set_time_zone_offset() {
    var current_time = new Date();
    $.cookie('time_zone', current_time.getTimezoneOffset());
}

But problem when someone not allow cookies or clear cookies of them browser at that time issue of timezone. Timezone get blank that i have issue in my application.

now, without timezone set in cookies, is there any way to get timezone in hidden field which post with form so i can save it.

Thanks

user1780370
  • 851
  • 1
  • 17
  • 27
  • you are doing just this to get the timezone of user and display time in local time to the user? – Jun Aid Dec 15 '15 at 07:15
  • 1
    There is already post, look at it if it helps you. http://stackoverflow.com/questions/12326570/rails-how-to-get-the-current-users-time-zone-when-using-heroku – Triveni Badgujar Dec 15 '15 at 07:17
  • You should check this out. [Here](http://stackoverflow.com/questions/25243240/how-can-i-use-javascript-to-get-the-local-time-in-a-rails-form) this is what you need. – Surge Dec 15 '15 at 07:21

1 Answers1

0

You can use JsTimezoneDetect Library for getting the timezone reliably.

Here's how you can use it in Rails app.

Cdn link.

Shifa Khan
  • 769
  • 6
  • 12