明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1134|回复: 16

[提问] 格林时间怎么转北京时间

[复制链接]
发表于 2019-7-15 12:21 | 显示全部楼层 |阅读模式
本帖最后由 taoyi0727 于 2019-7-15 12:40 编辑

如题  格林时间怎么转北京时间
只知道要+8小时  但是要算本月的天数 本年的天数  不知道这个函数要怎么写了
"Mon, 15 Jul 2019 04:39:35 GMT"

评分

参与人数 1明经币 +1 收起 理由
1291500406 + 1 给你弄2明经币

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2019-7-19 14:03 | 显示全部楼层
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 ...
  1. ;;说明:把字符串按特定字符分隔成表
  2. ;;参数:str:字符串
  3. ;;参数:del:字符串的分隔符
  4. ;;返回:表
  5. ;;用法:(T-string-separated "2012-07-01" "-")
  6. (defun T-string-separated (str del / lst pos)
  7.   (if (/= str nil)
  8.     (progn
  9.       (while (setq pos (vl-string-search del str))
  10.         (setq
  11.           lst (cons (substr str 1 pos) lst)
  12.           str (substr str (+ pos 1 (strlen del)))
  13.         )
  14.       )
  15.       (reverse (cons str lst))
  16.     )
  17.   )
  18. )
  19. ;;说明:时间计算
  20. ;;参数:time1:时间 [str]
  21. ;;参数:time2:时间 [str]
  22. ;;参数:model:+相加  -相减
  23. ;;参数:get:返回模式 1---字符串时间  2---表时间
  24. ;;返回:时间表 [list] 第1项 -1--退回1天 0--当天 1--前进1天
  25. ;;     (-1 "23:59:40")
  26. ;;     (-1 23 59 40)
  27. ;;用法:(T-time-calculate "23:50:50" "00:51:10" '+ 1)--->(1 "00:42:00")
  28. (defun T-time-calculate (time1 time2 model get / day h m s)
  29.   (setq time1 (mapcar 'atoi (T-string-separated time1 ":")))
  30.   (setq time2 (mapcar 'atoi (T-string-separated time2 ":")))
  31.   (setq day 0)
  32.   (cond
  33.     ((= model '+)
  34.       (if (>= (setq s (+ (nth 2 time1) (nth 2 time2))) 60);大于等于60秒
  35.         (progn
  36.           (setq m 1);分+1
  37.           (setq s (- s 60))
  38.         )
  39.       );计算秒
  40.       (if (if m
  41.             (>= (setq m (+ (nth 1 time1) (nth 1 time2) 1)) 60);大于等于60分
  42.             (>= (setq m (+ (nth 1 time1) (nth 1 time2))) 60);大于等于60分
  43.           )
  44.         (progn
  45.           (setq h 1);时+1
  46.           (setq m (- m 60))
  47.         )
  48.       );计算分
  49.       (if (if h
  50.             (>= (setq h (+ (nth 0 time1) (nth 0 time2) 1)) 24);大于等于24时
  51.             (>= (setq h (+ (nth 0 time1) (nth 0 time2))) 24);大于等于24时
  52.           )
  53.         (progn
  54.           (setq day 1);天+1
  55.           (setq h (- h 24))
  56.         )
  57.       );计算时
  58.     )
  59.     ((= model '-)
  60.       (if (< (setq s (- (nth 2 time1) (nth 2 time2))) 0);小于0秒
  61.         (progn
  62.           (setq m -1);分-1
  63.           (setq s (+ 60 s))
  64.         )
  65.       );计算秒
  66.       (if (if m
  67.             (< (setq m (- (nth 1 time1) (nth 1 time2) 1)) 0);小于0分
  68.             (< (setq m (- (nth 1 time1) (nth 1 time2))) 0);小于0分
  69.           )
  70.         (progn
  71.           (setq h -1);时-1
  72.           (setq m (+ m 60))
  73.         )
  74.       );计算分
  75.       (if (if h
  76.             (< (setq h (- (nth 0 time1) (nth 0 time2) 1)) 0);小于0时
  77.             (< (setq h (- (nth 0 time1) (nth 0 time2))) 0);小于0时
  78.           )
  79.         (progn
  80.           (setq day -1);时+1
  81.           (setq h 23)
  82.         )
  83.       );计算时
  84.     )
  85.   )
  86.   (cond
  87.     ((= get 1)
  88.       (list day (strcat
  89.                   (if (= (strlen (setq h (itoa h))) 1)
  90.                     (strcat "0" h)
  91.                     h
  92.                   )
  93.                   ":"
  94.                   (if (= (strlen (setq m (itoa m))) 1)
  95.                     (strcat "0" m)
  96.                     m
  97.                   )
  98.                   ":"
  99.                   (if (= (strlen (setq s (itoa s))) 1)
  100.                     (strcat "0" s)
  101.                     s
  102.                   )
  103.                 )
  104.       )
  105.     )
  106.     ((= get 2)
  107.       (list day h m s)
  108.     )
  109.   )
  110. )
  111. ;;说明:获取指定年份的总天数
  112. ;;参数:year:年 [int]
  113. ;;返回:当年的天数 [int]
  114. (defun T-get-year-days (year)
  115.   (if (numberp year)
  116.     (if (= 0 (rem year 4))
  117.       (if (= 0 (rem year 100))
  118.         (if (= 0 (rem year 400))
  119.           366
  120.           365
  121.         )
  122.         366
  123.       )
  124.       365
  125.     )
  126.   )
  127. )
  128. ;;说明:获取指定年份每月天数的关联表
  129. ;;参数:year:年 [int]
  130. ;;返回:每月天数的关联表 [list]
  131. (defun T-get-year-every-month-days (year)
  132.   (list
  133.     (cons 1 31)
  134.     (cons 2
  135.       (if (= 0 (rem year 4))
  136.         (if (= 0 (rem year 100))
  137.           (if (= 0 (rem year 400))
  138.             29
  139.             28
  140.           )
  141.           29
  142.         )
  143.         28
  144.       )
  145.     )
  146.     (cons 3 31)
  147.     (cons 4 30)
  148.     (cons 5 31)
  149.     (cons 6 30)
  150.     (cons 7 31)
  151.     (cons 8 31)
  152.     (cons 9 30)
  153.     (cons 10 31)
  154.     (cons 11 30)
  155.     (cons 12 31)
  156.   )
  157. )
  158. ;;说明:格林时间转北京时间
  159. ;;参数:date:格林时间 [str]
  160. ;;返回:北京时间 [str]
  161. ;;用法:(T-gmt-Beijing-time "Fri, 19 Jul 2019 05:57:20 GMT")
  162. (defun T-gmt-Beijing-time (date / day month n temp time week years)
  163.   (setq date (T-string-separated date " "))
  164.   (setq years (atoi (nth 3 date)));年
  165.   (setq month (nth 2 date));月
  166.   (cond
  167.     ((= (strcase month) "JAN")
  168.       (setq month 1)
  169.     )
  170.     ((= (strcase month) "FEB")
  171.       (setq month 2)
  172.     )
  173.     ((= (strcase month) "MAR")
  174.       (setq month 3)
  175.     )
  176.     ((= (strcase month) "APR")
  177.       (setq month 4)
  178.     )
  179.     ((= (strcase month) "MAY")
  180.       (setq month 5)
  181.     )
  182.     ((= (strcase month) "JUN")
  183.       (setq month 6)
  184.     )
  185.     ((= (strcase month) "JUL")
  186.       (setq month 7)
  187.     )
  188.     ((= (strcase month) "AUG")
  189.       (setq month 8)
  190.     )
  191.     ((= (strcase month) "SEP")
  192.       (setq month 9)
  193.     )
  194.     ((= (strcase month) "OCT")
  195.       (setq month 10)
  196.     )
  197.     ((= (strcase month) "NOW")
  198.       (setq month 11)
  199.     )
  200.     ((= (strcase month) "DEC")
  201.       (setq month 12)
  202.     )
  203.   )
  204.   (setq day (atoi (nth 1 date)));日
  205.   (setq time (nth 4 date));时间
  206.   (setq week (vl-list->string (reverse (cdr (reverse (vl-string->list (car date)))))));星期
  207.   (cond
  208.     ((= (strcase week) "MON");星期一
  209.       (setq week 0)
  210.     )
  211.     ((= (strcase week) "TUES");星期二
  212.       (setq week 1)
  213.     )
  214.     ((= (strcase week) "WED");星期三
  215.       (setq week 2)
  216.     )
  217.     ((= (strcase week) "WED");星期四
  218.       (setq week 3)
  219.     )
  220.     ((= (strcase week) "FRI");星期五
  221.       (setq week 4)
  222.     )
  223.     ((= (strcase week) "SAT");星期六
  224.       (setq week 5)
  225.     )
  226.     ((= (strcase week) "THU");星期日
  227.       (setq week 6)
  228.     )
  229.   )
  230.   (setq time (T-time-calculate time "08:00:00" '+ 1));北京时间
  231.   (if (= (car time) 1)
  232.     (progn
  233.       (setq temp (cdr (assoc month (T-get-year-every-month-days years))));本月天数
  234.       (if (> (setq day (+ day 1)) temp);大于本月天数
  235.         (progn
  236.           (setq day 1);1号
  237.           (setq n 1);加1月
  238.           (if (> (1+ week) 6)
  239.             (setq week (- (1+ week) 7))
  240.             (setq week (1+ week))
  241.           );星期
  242.         )
  243.       )
  244.     )
  245.   )
  246.   (if n
  247.     (if (< month 12)
  248.       (setq month (1+ month));加1月
  249.       (progn
  250.         (setq month (- (1+ month) 12));加1月减12月
  251.         (setq years (1+ years));加1年
  252.       )
  253.     )
  254.   )
  255.   (strcat
  256.     (itoa years);年
  257.     "-"
  258.     (if (= (strlen (setq month (itoa month))) 1)
  259.       (strcat "0" month)
  260.       month
  261.     );月
  262.     "-"
  263.     (if (= (strlen (setq day (itoa day))) 1)
  264.       (strcat "0" day)
  265.       day
  266.     );日
  267.     " "
  268.     (cadr time)
  269.     " "
  270.     (nth week '("星期一" "星期二" "星期三" "星期四" "星期五" "星期六" "星期日"))
  271.   )
  272. )
  273. (T-gmt-Beijing-time "Fri, 19 Jul 2019 05:57:20 GMT")--->"2019-07-19 13:57:20 星期五"
网上找了一些 自己写了一些   字符串分隔好像是黄大师的  写的最菜的那2个就是我自己写的
 楼主| 发表于 2019-7-19 12:19 | 显示全部楼层
谢谢 币就不给你了你太多了 都用不完
(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)
)
发表于 2019-7-19 11:16 | 显示全部楼层
本帖最后由 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(( = b2  2)(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)))))
(( = b2  4)(alert b4))(( = b2  6)(alert b4))(( = b2  9)(alert b4))(( = b2  11)(alert b4))
(T(alert (strcat "本月天数31\n剩余天数"  (rtos(- 31 b3)2 0)))))(princ))


评分

参与人数 1明经币 +1 收起 理由
自贡黄明儒 + 1 本题也只有用VBS最方便,很给力

查看全部评分

发表于 2019-7-17 07:51 | 显示全部楼层
计算天数除了二月份需要判断一下平年闰年,其他的按照常识来!
 楼主| 发表于 2019-7-17 15:41 | 显示全部楼层
fangmin723 发表于 2019-7-17 07:51
计算天数除了二月份需要判断一下平年闰年,其他的按照常识来!

就是不知道怎么计算当月有多少天
发表于 2019-7-18 09:31 | 显示全部楼层
本帖最后由 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天啊,这下应该会了吧,如果还不会,那就没救了
 楼主| 发表于 2019-7-18 11:22 | 显示全部楼层
谢谢你说的这个都知道  就是不知道闰年是怎么得来的  对日期这个东西 不看手机都不知道今天是几月几号
发表于 2019-7-18 14:30 | 显示全部楼层
taoyi0727 发表于 2019-7-18 11:22
谢谢你说的这个都知道  就是不知道闰年是怎么得来的  对日期这个东西 不看手机都不知道今天是几月几号

闰年是公历中的名词。闰年分为普通闰年和世纪闰年。
普通闰年:公历年份是4的倍数的,一般是闰年。(如2004年就是闰年);
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是世纪闰年,2000年是世纪闰年);
——百度百科

PS:虽然百度无耻,但用百度查东西并不无耻。
 楼主| 发表于 2019-7-19 08:49 | 显示全部楼层
耗了2天 搞定了 谢谢大家的帮忙
发表于 2019-7-19 10:50 | 显示全部楼层
taoyi0727 发表于 2019-7-19 08:49
耗了2天 搞定了 谢谢大家的帮忙

这个要两天也太久了吧
 楼主| 发表于 2019-7-19 11:10 | 显示全部楼层
1291500406 发表于 2019-7-19 10:50
这个要两天也太久了吧

水平有限  对时间这个东西 没有概念
你看明经币就知道啦 你的是用不完  我的每次都要用激情换
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 17:19 , Processed in 6.733805 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表