明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: taoyi0727

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

[复制链接]
 楼主| 发表于 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 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 14:20 | 显示全部楼层
或许您可参研 Julian.Lsp
 楼主| 发表于 2019-7-19 15:02 | 显示全部楼层
发表于 2019-7-19 16:27 | 显示全部楼层

我这儿在 Express之下
...\Express\julian.Lsp
 楼主| 发表于 2019-7-19 17:10 | 显示全部楼层
Andyhon 发表于 2019-7-19 16:27
我这儿在 Express之下
...\Express\julian.Lsp

果然有   CAD安装目录下重来没有去翻过  
谢了
发表于 2022-3-8 09:35 | 显示全部楼层
本帖最后由 1291500406 于 2022-3-8 10:21 编辑
taoyi0727 发表于 2019-7-19 14:03
网上找了一些 自己写了一些   字符串分隔好像是黄大师的  写的最菜的那2个就是我自己写的

  1. ---> "2019年7月19日 13:57:20 星期五"
  2. (T-gmt-Beijing-time "Fri, 19 Jul 2019 05:57:20 GMT")--->"2019-07-19 13:57:20 星期五"太复杂了

LISP调用javascript函数方法举例 - AutoLISP/Visual LISP 编程技术 - CAD论坛 - 明经CAD社区 - Powered by Discuz! (mjtd.com)




您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 21:54 , Processed in 0.247366 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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