RSS

Converting Time to IST in Rails

13 Jan

clock

OK, in this blog I am going to say how to convert your time to Indian Standard Time. Most Rails servers return their time in UTC, but if you are developing application for a Indian firm they would like it in IST.

Lets say in your application you print your time on the webpage like this:

<%= Time.new %>

This will surely give the time in UTC like 2012-01-13 15:19:43 UTC, but you need it in IST, to do so add this method in our application helper

def ist(time)
  time.in_time_zone(TZInfo::Timezone.get('Asia/Kolkata'))
end

In view just modify the code as follows

<%= ist Time.new %>

And thats it, you will get time like 2012-01-13 20:49:43 +0530

Advertisements
 
Leave a comment

Posted by on January 13, 2012 in Ruby, Ruby On Rails, Web Tech

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: