格林时间怎么转北京时间
本帖最后由 taoyi0727 于 2019-7-15 12:40 编辑如题格林时间怎么转北京时间
只知道要+8小时但是要算本月的天数 本年的天数不知道这个函数要怎么写了
"Mon, 15 Jul 2019 04:39:35 GMT"
1291500406 发表于 2019-7-19 11:16
(defun c:bb ( / b b1 b2 b3 b4)
(setq b(rtos(getvar ' cdate)2 0)b1 (fix(atof(substr b 1 4)))b2(fix ...
;;说明:把字符串按特定字符分隔成表
;;参数:str:字符串
;;参数:del:字符串的分隔符
;;返回:表
;;用法:(T-string-separated "2012-07-01" "-")
(defun T-string-separated (str del / lst pos)
(if (/= str nil)
(progn
(while (setq pos (vl-string-search del str))
(setq
lst (cons (substr str 1 pos) lst)
str (substr str (+ pos 1 (strlen del)))
)
)
(reverse (cons str lst))
)
)
)
;;说明:时间计算
;;参数:time1:时间
;;参数:time2:时间
;;参数:model:+相加-相减
;;参数:get:返回模式 1---字符串时间2---表时间
;;返回:时间表 第1项 -1--退回1天 0--当天 1--前进1天
;; (-1 "23:59:40")
;; (-1 23 59 40)
;;用法:(T-time-calculate "23:50:50" "00:51:10" '+ 1)--->(1 "00:42:00")
(defun T-time-calculate (time1 time2 model get / day h m s)
(setq time1 (mapcar 'atoi (T-string-separated time1 ":")))
(setq time2 (mapcar 'atoi (T-string-separated time2 ":")))
(setq day 0)
(cond
((= model '+)
(if (>= (setq s (+ (nth 2 time1) (nth 2 time2))) 60);大于等于60秒
(progn
(setq m 1);分+1
(setq s (- s 60))
)
);计算秒
(if (if m
(>= (setq m (+ (nth 1 time1) (nth 1 time2) 1)) 60);大于等于60分
(>= (setq m (+ (nth 1 time1) (nth 1 time2))) 60);大于等于60分
)
(progn
(setq h 1);时+1
(setq m (- m 60))
)
);计算分
(if (if h
(>= (setq h (+ (nth 0 time1) (nth 0 time2) 1)) 24);大于等于24时
(>= (setq h (+ (nth 0 time1) (nth 0 time2))) 24);大于等于24时
)
(progn
(setq day 1);天+1
(setq h (- h 24))
)
);计算时
)
((= model '-)
(if (< (setq s (- (nth 2 time1) (nth 2 time2))) 0);小于0秒
(progn
(setq m -1);分-1
(setq s (+ 60 s))
)
);计算秒
(if (if m
(< (setq m (- (nth 1 time1) (nth 1 time2) 1)) 0);小于0分
(< (setq m (- (nth 1 time1) (nth 1 time2))) 0);小于0分
)
(progn
(setq h -1);时-1
(setq m (+ m 60))
)
);计算分
(if (if h
(< (setq h (- (nth 0 time1) (nth 0 time2) 1)) 0);小于0时
(< (setq h (- (nth 0 time1) (nth 0 time2))) 0);小于0时
)
(progn
(setq day -1);时+1
(setq h 23)
)
);计算时
)
)
(cond
((= get 1)
(list day (strcat
(if (= (strlen (setq h (itoa h))) 1)
(strcat "0" h)
h
)
":"
(if (= (strlen (setq m (itoa m))) 1)
(strcat "0" m)
m
)
":"
(if (= (strlen (setq s (itoa s))) 1)
(strcat "0" s)
s
)
)
)
)
((= get 2)
(list day h m s)
)
)
)
;;说明:获取指定年份的总天数
;;参数:year:年
;;返回:当年的天数
(defun T-get-year-days (year)
(if (numberp year)
(if (= 0 (rem year 4))
(if (= 0 (rem year 100))
(if (= 0 (rem year 400))
366
365
)
366
)
365
)
)
)
;;说明:获取指定年份每月天数的关联表
;;参数:year:年
;;返回:每月天数的关联表
(defun T-get-year-every-month-days (year)
(list
(cons 1 31)
(cons 2
(if (= 0 (rem year 4))
(if (= 0 (rem year 100))
(if (= 0 (rem year 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)
)
)
;;说明:格林时间转北京时间
;;参数:date:格林时间
;;返回:北京时间
;;用法:(T-gmt-Beijing-time "Fri, 19 Jul 2019 05:57:20 GMT")
(defun T-gmt-Beijing-time (date / day month n temp time week years)
(setq date (T-string-separated date " "))
(setq years (atoi (nth 3 date)));年
(setq month (nth 2 date));月
(cond
((= (strcase month) "JAN")
(setq month 1)
)
((= (strcase month) "FEB")
(setq month 2)
)
((= (strcase month) "MAR")
(setq month 3)
)
((= (strcase month) "APR")
(setq month 4)
)
((= (strcase month) "MAY")
(setq month 5)
)
((= (strcase month) "JUN")
(setq month 6)
)
((= (strcase month) "JUL")
(setq month 7)
)
((= (strcase month) "AUG")
(setq month 8)
)
((= (strcase month) "SEP")
(setq month 9)
)
((= (strcase month) "OCT")
(setq month 10)
)
((= (strcase month) "NOW")
(setq month 11)
)
((= (strcase month) "DEC")
(setq month 12)
)
)
(setq day (atoi (nth 1 date)));日
(setq time (nth 4 date));时间
(setq week (vl-list->string (reverse (cdr (reverse (vl-string->list (car date)))))));星期
(cond
((= (strcase week) "MON");星期一
(setq week 0)
)
((= (strcase week) "TUES");星期二
(setq week 1)
)
((= (strcase week) "WED");星期三
(setq week 2)
)
((= (strcase week) "WED");星期四
(setq week 3)
)
((= (strcase week) "FRI");星期五
(setq week 4)
)
((= (strcase week) "SAT");星期六
(setq week 5)
)
((= (strcase week) "THU");星期日
(setq week 6)
)
)
(setq time (T-time-calculate time "08:00:00" '+ 1));北京时间
(if (= (car time) 1)
(progn
(setq temp (cdr (assoc month (T-get-year-every-month-days years))));本月天数
(if (> (setq day (+ day 1)) temp);大于本月天数
(progn
(setq day 1);1号
(setq n 1);加1月
(if (> (1+ week) 6)
(setq week (- (1+ week) 7))
(setq week (1+ week))
);星期
)
)
)
)
(if n
(if (< month 12)
(setq month (1+ month));加1月
(progn
(setq month (- (1+ month) 12));加1月减12月
(setq years (1+ years));加1年
)
)
)
(strcat
(itoa years);年
"-"
(if (= (strlen (setq month (itoa month))) 1)
(strcat "0" month)
month
);月
"-"
(if (= (strlen (setq day (itoa day))) 1)
(strcat "0" day)
day
);日
" "
(cadr time)
" "
(nth week '("星期一" "星期二" "星期三" "星期四" "星期五" "星期六" "星期日"))
)
)
(T-gmt-Beijing-time "Fri, 19 Jul 2019 05:57:20 GMT")--->"2019-07-19 13:57:20 星期五"网上找了一些 自己写了一些 字符串分隔好像是黄大师的写的最菜的那2个就是我自己写的
谢谢 币就不给你了你太多了 都用不完:lol
(defun c:bb (/ b b1 b2 b3)
(setq
b(rtos (getvar "cdate") 2 0);当前日期
b1 (fix (atof (substr b 1 4)));年
b2 (fix (atof (substr b 5 2)));月
b3 (fix (atof (substr b 7 2)));日
)
(cond
((= b2 2);2月
(if (= (rem b1 4.0) 0);能整除
(alert (strcat "本月天数29\n剩余天数" (rtos (- 29 b3) 2 0)))
(alert (strcat "本月天数28\n剩余天数" (rtos (- 28 b3) 2 0)))
)
)
((or
(= b2 4);4月
(= b2 6);6月
(= b2 9);9月
(= b2 11);11月
)
(alert (strcat "本月天数30\n剩余天数" (rtos (- 30 b3) 2 0)))
)
(T
(alert (strcat "本月天数31\n剩余天数" (rtos (- 31 b3) 2 0)))
)
)
(princ)
) 本帖最后由 1291500406 于 2019-7-19 11:28 编辑
taoyi0727 发表于 2019-7-19 11:10
水平有限对时间这个东西 没有概念
你看明经币就知道啦 你的是用不完我的每次都要用激情换
(defun c:bb ( / b b1 b2 b3 b4)
(setq b(rtos(getvar ' cdate)2 0)b1 (fix(atof(substr b 1 4)))b2(fix(atof(substr b 5 2)))b3(fix(atof(substr b 7 2)))
b4(strcat "本月天数30\n剩余天数"(rtos(- 30 b3)2 0)))(cond(( = b22)(if (=(-( / b1 4.0)( / b1 4))0)
(alert(strcat "本月天数29\n剩余天数" (rtos(- 29 b3)2 0)))(alert (strcat "本月天数28\n剩余天数" (rtos(- 28 b3)2 0)))))
(( = b24)(alert b4))(( = b26)(alert b4))(( = b29)(alert b4))(( = b211)(alert b4))
(T(alert (strcat "本月天数31\n剩余天数"(rtos(- 31 b3)2 0)))))(princ))
计算天数除了二月份需要判断一下平年闰年,其他的按照常识来! fangmin723 发表于 2019-7-17 07:51
计算天数除了二月份需要判断一下平年闰年,其他的按照常识来!
就是不知道怎么计算当月有多少天 本帖最后由 fangmin723 于 2019-7-18 09:34 编辑
taoyi0727 发表于 2019-7-17 15:41
就是不知道怎么计算当月有多少天
1、3、5、7、8、10、12是31天,4、6、9、11有30天啊,2月份通过去平润年去判断是28天,还是29天啊,这下应该会了吧,如果还不会,那就没救了 谢谢你说的这个都知道就是不知道闰年是怎么得来的对日期这个东西 不看手机都不知道今天是几月几号 taoyi0727 发表于 2019-7-18 11:22
谢谢你说的这个都知道就是不知道闰年是怎么得来的对日期这个东西 不看手机都不知道今天是几月几号
闰年是公历中的名词。闰年分为普通闰年和世纪闰年。
普通闰年:公历年份是4的倍数的,一般是闰年。(如2004年就是闰年);
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是世纪闰年,2000年是世纪闰年);
——百度百科
PS:虽然百度无耻,但用百度查东西并不无耻。 耗了2天 搞定了 谢谢大家的帮忙 taoyi0727 发表于 2019-7-19 08:49
耗了2天 搞定了 谢谢大家的帮忙
这个要两天也太久了吧 1291500406 发表于 2019-7-19 10:50
这个要两天也太久了吧
水平有限对时间这个东西 没有概念
你看明经币就知道啦 你的是用不完我的每次都要用激情换
页:
[1]
2