DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Ruby On Rails Jalali Date (Shamsi Date)

11.10.2009
| 6247 views |
  • submit to reddit
        This is Jalali-Gregorian (Shamsi-Gregorian) date converter and also Jalali Date tag creator. Also it extends rails FormBuilder.

You can easily have select Jalai Date tags in your ror applications and convert the date easily by following codes:

Time.now  #=> Sat Nov 07 16:18:16 +0330 2009
jalali_date = JalaliDate.to_jalali(Time.now)
jalali_date.year  #=> 1388
gregorian_date = jalali_date.to_gregorian #=> Sat Nov 07 00:00:00 +0330 2009 

It also extend Rails Form Helper with jalali date select tag:
<% form_for(@post) do |f| %>
   <%= f.jalali_date :created_at, :prefix=>'start_date' %>
<% end %> 
You can get the code from <a href='http://arashkarimzadeh.com/codes/11-ruby-on-rails/27-ruby-on-rails-jalali-date-shamsi-date.html'>Jalali Convertor</a>