明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 334|回复: 4

【K:GetWebTime】获取网络时间并格式化

  [复制链接]
发表于 2024-4-12 21:50 | 显示全部楼层 |阅读模式
函数来自此贴,仅作优化:http://bbs.mjtd.com/forum.php?mo ... %CD%F8%C2%E7&page=1
  1. ;获取网页URL的网络时间,如果不成功返回Nil
  2. ;(K:GetWebTime "https://www.baidu.com" "Date")
  3. (defun K:GetWebTime (URL Headers / obj RtnVar)
  4.   (if (setq obj (vlax-create-object "winhttp.winhttprequest.5.1"))
  5.       (progn
  6.         (setq RtnVar (vl-catch-all-apply
  7.                       '(lambda ()
  8.                           (vlax-invoke-method obj "open" "head" URL :vlax-false)
  9.                           (vlax-invoke obj "send")
  10.                           (if (= 200 (vlax-get-property obj "status"))
  11.                               (mapcar
  12.                                 '(lambda (h / r)
  13.                                   (setq r (vl-catch-all-apply 'vlax-invoke-method (list obj "getresponseheader" h)))
  14.                                   (cons h (if (not (vl-catch-all-error-p r)) (progn r)))
  15.                                 )
  16.                                 (list Headers)
  17.                               )
  18.                           )
  19.                       )
  20.                     )
  21.         )
  22.         (vlax-release-object obj)
  23.         (if (and RtnVar (not (vl-catch-all-error-p RtnVar))) ;不是错误
  24.             (cdar RtnVar)
  25.         )
  26.       )
  27.   )
  28. )
  29. ;根据分隔符拆分字符串@LeeMac
  30. (defun K:STR->Lst (STR Del / len Lst pos)
  31.   (setq len (1+ (strlen Del)))
  32.   (while (setq pos (vl-string-search Del STR))
  33.     (setq Lst (cons (substr STR 1 pos) Lst)
  34.           STR (substr STR (+ pos len))
  35.     )
  36.   )
  37.   (reverse (cons STR Lst))
  38. )
  39. ;格式化获取到的网络时间OriSTR
  40. (defun K:FmtWebTime (OriSTR / STRLst Wek Date Moth Year CurTim)
  41.   (if (and OriSTR (setq STRLst (K:STR->Lst OriSTR " ")))
  42.       (progn
  43.         (setq Wek (strcase (substr (nth 0 STRLst) 1 3)));只要前三个字母
  44.         (setq Date (nth 1 STRLst)
  45.               Moth (strcase (nth 2 STRLst))
  46.               Year (nth 3 STRLst)
  47.         )
  48.         (setq CurTim (nth 4 STRLst));当前时间
  49.         (setq Moth
  50.           (cdr
  51.             (assoc Moth
  52.                 (list
  53.                   (cons "JAN" "01")
  54.                   (cons "FEB" "02")
  55.                   (cons "MAR" "03")
  56.                   (cons "APR" "04")
  57.                   (cons "MAY" "05")
  58.                   (cons "JUN" "06")
  59.                   (cons "JUL" "07")
  60.                   (cons "AUG" "08")
  61.                   (cons "SEP" "09")
  62.                   (cons "OCT" "10")
  63.                   (cons "NOV" "11")
  64.                   (cons "DEC" "12")
  65.                 )
  66.             )
  67.           )
  68.         );几月份
  69.         (setq Wek
  70.             (cdr
  71.               (assoc Wek
  72.                 (list (cons "MON" "01")
  73.                       (cons "TUE" "02")
  74.                       (cons "WED" "03")
  75.                       (cons "THU" "04")
  76.                       (cons "FRI" "05")
  77.                       (cons "SAT" "06")
  78.                       (cons "SUN" "07")
  79.                 )
  80.               )
  81.             )
  82.         );周几
  83.       )
  84.   )
  85.   (if OriSTR (progn (strcat Year Moth Date)));输出年月日
  86. )




用法:
  1. (K:FmtWebTime (K:GetWebTime "https://www.baidu.com" "Date"))


评分

参与人数 1明经币 +1 收起 理由
ssyfeng + 1 赞一个!

查看全部评分

发表于 2024-4-12 23:49 | 显示全部楼层
感谢大佬分享
发表于 2024-4-13 14:02 | 显示全部楼层
插件加密的一种方式
发表于 2024-4-13 20:08 | 显示全部楼层

感谢大佬分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-1 13:26 , Processed in 0.926467 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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