0
我執行此代碼:'Time.at(秒)' 給出不同的時間 '的級分(秒/ 60,秒%60)'
t = DateTime.strptime('1:00:23', '%H:%M:%S')
t1 = DateTime.strptime('2:02:40', '%H:%M:%S')
t2 = t1.to_time - t.to_time
time_new = "#{(t2/3600).to_i}" + ":" +"#{((t2/60)%60).to_i}" + ":" + "#{(t2%60).to_i}"
time_units = time_new.split(':')
我得到:
Time.at(t2).strftime("%H:%M:%S")
# => 06:32:17
"#{time_units[0]} hours, #{time_units[1]} minutes and #{time_units[2]} seconds"
# => 1 hours, 2 minutes and 17 seconds
這是非常不同的。爲什麼Time.at(seconds)
增加5小時30分鐘?
嘗試'Time.zone.at(T2).strftime( 「%H:%M:%S」)' –
這是因爲你的時區 – fangxing
@ Md.FarhanMemon嘗試「Time.zone .AT(T2).strftime( 「%H:%M:%S」)」。它給了我一個未定義的方法'區域'的時間:類(NoMethodError) – Tim