Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created August 28, 2011 00:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndianGuru/1176084 to your computer and use it in GitHub Desktop.
Save IndianGuru/1176084 to your computer and use it in GitHub Desktop.
JRuby programs
# First get the current local time
t = Time.now
# to get day, month and year with century
# also hour, minute and second
puts t.strftime("%d/%m/%Y %H:%M:%S")
# You can use the upper case A and B to get the full
# name of the weekday and month, respectively
puts t.strftime("%A")
puts t.strftime("%B")
# You can use the lower case a and b to get the abbreviated
# name of the weekday and month, respectively
puts t.strftime("%a")
puts t.strftime("%b")
# 24 hour clock and Time zone name
puts t.strftime("at %H:%M %Z")
JS = Java::java.lang.System
os = JS.get_property 'os.name'
home = JS.get_property 'java.home'
mem = Java::java.lang.Runtime.get_runtime.free_memory
puts "Running on #{os}"
puts "Java home is #{home}"
puts "#{mem} bytes available in JVM"
require 'java'
os = java.lang.System.get_property 'os.name'
home = java.lang.System.get_property 'java.home'
mem = java.lang.Runtime.get_runtime.free_memory
puts "Running on #{os}"
puts "Java home is #{home}"
puts "#{mem} bytes available in JVM"
require 'java'
#java_import 'java.util.Date'
java_import('java.util.Date') { |pkg,name| 'JDate' }
java_import 'java.text.DateFormat'
date = JDate.new
date_format = DateFormat.get_date_instance
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