天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 55|回复: 0

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

[复制链接]
  • TA的每日心情
    开心
    半小时前
  • 签到天数: 82 天

    [LV.6]常住居民II

    1572

    主题

    204

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
    发表于 2024-4-13 17:34:07 | 显示全部楼层 |阅读模式

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

    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. )
    复制代码

     

     

     

     

    【K:GetWebTime】获取网络时间并格式化
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-16 08:37 , Processed in 0.057315 second(s), 21 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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