如题,百度一圈也没找到创建和解析 13 位 unix 时间戳的方法,最后自己写了个方法,如下:
class Time
alias :to_ii to_i
def to_i(i=10)
if i > 10
Integer(("%10.#{i-10}f" % self.to_f).delete '.')
else
self.to_ii
end
end
def Time.att(i)
if i.to_s.length > 10
s = i.to_s
s[10,0] = '.'
at(s.to_f)
end
end
end
a = Time.new
a = a.to_i(13) #生成13位unix时间戳
puts a
puts Time.att(a) #解析时间戳
另请教大神,是否有系统自带的方法可以使用?
PS:顺便吐糟下中文社区的搜索,为何不换成必应或百度呢?