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

后端 未结 7 481
闹比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:41

    require 'date'
    
    p DateTime.now.strftime('%s') # "1384526946" (seconds)
    p DateTime.now.strftime('%Q') # "1384526946523" (milliseconds)
    

提交回复
热议问题