Sort UTC timestamp
I want to pull the latest UTC time from an array which contains various
UTC time. I could compare two time stamps in UTC as below:
#!/usr/bin/ruby
require "time"
a=Time.parse("2013-05-03 16:25:35 UTC")
b=Time.parse("2013-09-07 06:51:24 UTC")
if b < a
puts "latest time is #{a}"
else
puts "latest time is #{b}"
end
Output:
latest time is 2013-09-07 06:51:24 UTC
This way it is OK to compare only two time stamps. But my array contains
more than 2 UTC time stamps and I need to chose the latest one. Here is
the list of Array elements:
2013-04-30 12:13:20 UTC
2013-09-07 06:51:24 UTC
2013-05-03 16:25:35 UTC
2013-08-01 07:28:59 UTC
2013-04-09 13:42:36 UTC
2013-09-04 11:40:20 UTC
2013-07-01 06:47:52 UTC
2013-05-03 16:21:54 UTC
I want to chose the latest time from array which would be 2013-09-07
06:51:24 UTC
QUESTION: How to compare all the array elements against each other on
basis of UTC time ?
thanks.
No comments:
Post a Comment