计算时间差,返回两个时间点之间的分钟数
大部分是借鉴了这个帖子:http://bbs.mjtd.com/forum.php?mod=viewthread&tid=95113&highlight=%CA%B1%BC%E4%B2%EE改成了返回分钟数
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;日期差计算,借鉴http://bbs.mjtd.com/forum.php?mod=viewthread&tid=95113&highlight=%CA%B1%BC%E4%B2%EE
(defun dt-dates (oneyear)
(if (numberp oneyear)
(if (= 0 (rem oneyear 4))
(if (= 0 (rem oneyear 100))
(if (= 0 (rem oneyear 400))
366
365
)
366
)
365
)
)
)
;;;返回指定年份每个月和对应的天数的关联表
(defun dt-everyMonth-list (spacYear)
(list
(cons 1 31)
(cons 2
(if (= 0 (rem spacYear 4))
(if (= 0 (rem spacYear 100))
(if (= 0 (rem spacYear 400))
29
28
)
29
)
28
)
)
(cons 3 31)
(cons 4 30)
(cons 5 31)
(cons 6 30)
(cons 7 31)
(cons 8 31)
(cons 9 30)
(cons 10 31)
(cons 11 30)
(cons 12 31)
)
)
;;;返回指定日期是当年的第几天
;;;spyear指定年份
;;;spmonth 指定月份
;;;spdate指定日期
(defun dt-nthdate (spyear spmonth spdate / ddList somemon sumdates)
(if (and (numberp spyear) (numberp spmonth) (numberp spdate))
(progn
(setq ddList (dt-everyMonth-list spyear)
somemon1
sumdates 0
)
(while (< somemon spmonth)
(setq sumdates (+ (cdr (assoc somemon ddList)) sumdates)
somemon(1+ somemon)
)
)
(+ sumdates spdate)
)
)
)
;;;两个日期之间的天数例如(DT-DIST '(2019 3 2) '(2018 5 2))
(defun dt-dist (mList nList / maxyear minyear maxList minList someyear
sumdate)
(if (and (numberp (caddr mList)) (numberp (caddr nList)))
(if (/= (car mList) (car nList))
(progn
(setq maxyear (max (car mList) (car nList))
minyear (min (car mList) (car nList))
maxList (assoc maxyear (list mList nList))
minList (assoc minyear (list mList nList))
)
(setq someyear (+ minyear 1)
sumdate0
)
(while (< someyear maxyear)
(setq sumdate (+ (dt-dates someyear) sumdate)
someyear (1+ someyear)
)
)
(+ (- (dt-dates minyear)
(dt-nthdate minyear (cadr minList) (caddr minList))
)
sumdate
(dt-nthdate maxyear (cadr maxList) (caddr maxList))
)
)
(abs (- (dt-nthdate (car mList) (cadr mList) (caddr mList))
(dt-nthdate (car nList) (cadr nList) (caddr nList))
)
)
)
)
)
(defun time_format(t1)
(list
(list "y"(atoi(substr t1 1 4)))
(list "mo"(atoi(substr t1 5 2)))
(list "d"(atoi (substr t1 7 2)) )
(list "h"(atoi(substr t1 10 2)) )
(list "mi"(atoi (substr t1 12 2)))))
(defun time_value_get(ftime lab)
(nth 1 (assoc lab ftime)))
(defun time-time(t1 t2);;;;时间相减,返回分钟“20190919-1739”,t1较大时间,t2较小时间
(setq t1lst(time_format t1)
t2lst(time_format t2))
(setq daydist(dt-dist (list (time_value_get t1lst "y")(time_value_get t1lst "mo")(time_value_get t1lst "d"))
(list (time_value_get t2lst "y")(time_value_get t2lst "mo")(time_value_get t2lst "d"))));;;;天数差
( setq mdist (+(* daydist 24 60)
(* 60(- (time_value_get t1lst "h")(time_value_get t2lst "h")))
(* 1(- (time_value_get t1lst "mi")(time_value_get t2lst "mi")))))
mdist
)
示例:(time-time"20190919-1739" "20180819-1739" )
返回:570240
页:
[1]