与时间的指数一起工作

时间:2015-11-11 15:32:29

标签: ruby math

我有一个字符串如下:

#!/usr/bin/env python
from socket import socket, AF_PACKET, SOCK_RAW
s = socket(AF_PACKET, SOCK_RAW)
#s.bind(("eth1", 0))

# We're putting together an ethernet frame here, 
# NOTE: Not a full TCP frame, this is important to remember!
src_addr = "\x01\x02\x03\x04\x05\x06"
dst_addr = "\x01\x02\x03\x04\x05\x06"
payload = ("["*30)+"PAYLOAD"+("]"*30)
checksum = "\x1a\x2b\x3c\x4d"
ethertype = "\x08\x01"

s.send(dst_addr+src_addr+ethertype+payload+checksum)

从右到左,我的工作功率为60,因为我希望从小时,分钟,秒获得总秒数。

这就是我的尝试:

"00:48:22" 

结果已关闭。它应该是2902.知道我做错了吗?

3 个答案:

答案 0 :(得分:2)

您的算法有点混乱且容易出错。 这将给你正确的答案:

Uncaught TypeError: string is not a function

答案 1 :(得分:1)

您正在添加应该乘以的位置

EOF

答案 2 :(得分:0)

require 'date'

d = Date.today
(Time.new(d.year,d.month,d.day,*str.split(':').map(&:to_i))-d.to_time).to_i
  #=> 2902