当前位置: 代码迷 >> PB >> PB中怎么实现时间的相加
  详细解决方案

PB中怎么实现时间的相加

热度:274   发布时间:2016-04-29 10:40:02.0
PB中如何实现时间的相加
如题:
例如:time1 = '9:27', time2 = '9:57'
要的结果为 time1 + time2 = '19:23'


------解决方案--------------------
没有直接可用的函数,只能将time1和time2分部拆开为两部分,然后9+9=18,27+57=24进1
------解决方案--------------------
或者,都转换为秒数再相加
C/C++ code
string time1 = '9:27', time2 = '9:57', time_addtime lt1, lt2long lllt1 = time('00:' + time1); lt2 = time('00:' + time2)ll = minute(lt1) * 60 + minute(lt2) * 60 + second(lt1) + second(lt2)time_add = string(int(ll / 60)) + ":" + string(mod(ll , 60))messagebox('', time_add)
------解决方案--------------------
C/C++ code
time    ltm_time1, ltm_time2ltm_time1 = time('9:27')ltm_time2 = time('9:57')RelativeTime(ltm_time1, hour(ltm_time2) * 3600 + minute(ltm_time2) * 60 + second(ltm_time2) - 1)
------解决方案--------------------
messagebox("",string(RelativeTime(23:59:58, 3)))

得到 23:59:59 

Return value 

Time. Returns the time that occurs n seconds after time if n is greater than 0. Returns the time that occurs n seconds before time if n is less than 0. The maximum return value is 23:59:59. If any argument's value is null, RelativeTime returns null.

跨天情况得额外判断
------解决方案--------------------
转化成秒 然后mod(sec,86400) 再转时间
  相关解决方案