-
-
Save kares/c0ba5c7a7e4caa121134 to your computer and use it in GitHub Desktop.
Ruby Time vs Java Date millisecond interpretation
This file contains 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
>> 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