Skip to content

Instantly share code, notes, and snippets.

@omegahm
Last active May 22, 2019 09:20
Show Gist options
  • Save omegahm/98db39ccbf8a0c05ed2f91cda271fa32 to your computer and use it in GitHub Desktop.
Save omegahm/98db39ccbf8a0c05ed2f91cda271fa32 to your computer and use it in GitHub Desktop.
Time differences?
def run
t = 12.hours.from_now
n = Time.zone.now
puts t
puts n
puts (t.to_datetime - n.to_datetime)
puts (t.to_datetime - n.to_datetime).to_f
(t.to_datetime - n.to_datetime).ceil
end
## JRuby
> run
2019-05-22 21:02:26 UTC
2019-05-22 09:02:26 UTC
193/1000
0.193
=> 1
> run
2019-05-22 21:02:29 UTC
2019-05-22 09:02:29 UTC
237/1000
0.237
=> 1
> run
2019-05-22 21:02:31 UTC
2019-05-22 09:02:31 UTC
4/25
0.16
=> 1
> run
2019-05-22 21:02:32 UTC
2019-05-22 09:02:32 UTC
95558399/86400000
1.105999988425926
=> 2
## MRI
> run
2019-05-22 21:04:38 UTC
2019-05-22 09:04:38 UTC
1799999996771/3600000000000
0.49999999910305554
=> 1
> run
2019-05-22 21:04:38 UTC
2019-05-22 09:04:38 UTC
863999998321/1728000000000
0.49999999902835646
=> 1
> run
2019-05-22 21:04:39 UTC
2019-05-22 09:04:39 UTC
43199999891837/86400000000000
0.4999999987481134
=> 1
> run
2019-05-22 21:04:40 UTC
2019-05-22 09:04:40 UTC
21599999947433/43200000000000
0.4999999987831713
=> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment