Skip to content

Instantly share code, notes, and snippets.

@migane
Created September 15, 2012 20:09
Show Gist options
  • Save migane/3729548 to your computer and use it in GitHub Desktop.
Save migane/3729548 to your computer and use it in GitHub Desktop.
Date locale/us in jruby
# jruby01.rb
require 'java'
java_import('java.util.Date') { |pkg, name| 'JDate' }
# To get the locales
java_import('java.util.Locale') { |pkg, name| 'JLocale'}
java_import('java.text.DateFormat')
# Get the date in local format
date = JDate.new
date_format = DateFormat.get_date_instance
date_locale = date_format .format date
puts date_locale
# Get the date in us format
date_format = DateFormat.get_date_instance(DateFormat::LONG, JLocale::US)
date_us = date_format .format date
puts date_us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment