Skip to content

Instantly share code, notes, and snippets.

@kares
Created December 11, 2013 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kares/c0ba5c7a7e4caa121134 to your computer and use it in GitHub Desktop.
Save kares/c0ba5c7a7e4caa121134 to your computer and use it in GitHub Desktop.
Ruby Time vs Java Date millisecond interpretation
>> time = Time.new -1, 12, 31, 23, 59, 59, 0
=> -0001-12-31 23:59:59 UTC
>> time.to_f
=> -62167219201.0
>> time_millis = (time.to_f * 1000).round
=> -62167219201000
>> jdate = time.to_java
=> #<Java::JavaUtil::Date:0x5a360f2b>
>> jdate.toString
=> "Sat Jan 03 00:59:59 CET 1"
>> jdate.getTime
=> -62167219201000
>> java.text.SimpleDateFormat.new("yyyy-MM-dd HH:mm:ss").format jdate
=> "0001-01-03 00:59:59"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment