首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

PB中怎么实现时间的相加

2012-03-06 
PB中如何实现时间的相加如题:例如:time1 9:27, time2 9:57要的结果为 time1 + time2 19:23[解

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) 再转时间

热点排行