secret
Created

Ruby Time vs Java Date millisecond interpretation

  • Download Gist
date-time.session.out
1 2 3 4 5 6 7 8 9 10 11 12 13 14
>> 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"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.