Created
August 28, 2011 00:56
-
-
Save IndianGuru/1176084 to your computer and use it in GitHub Desktop.
JRuby programs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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