How to get the current time as 13-digit integer in Ruby?

后端 未结 7 499
闹比i
闹比i 2020-12-04 11:35

I have this jQuery function that returns the current time as the number of milliseconds since the epoch (Jan 1, 1970):

time = new Date().getTime         


        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 12:23

    Get a Time object with Time.now, calling #to_i returns a Unix timestamp (seconds from epoch). #to_f gives fractional seconds which you can use to get milliseconds from epoch:

    Time.now.to_f * 1000
    

提交回复
热议问题