【K:GetWebTime】获取网络时间并格式化
(K:FmtWebTime (K:GetWebTime "https://www.baidu.com" "Date"));获取网页URL的网络时间,如果不成功返回Nil
;(K:GetWebTime "https://www.baidu.com" "Date")
(defun K:GetWebTime (URL Headers / obj RtnVar)
(if (setq obj (vlax-create-object "winhttp.winhttprequest.5.1"))
(progn
(setq RtnVar (vl-catch-all-apply
'(lambda ()
(vlax-invoke-method obj "open" "head" URL :vlax-false)
(vlax-invoke obj "send")
(if (= 200 (vlax-get-property obj "status"))
(mapcar
'(lambda (h / r)
(setq r (vl-catch-all-apply 'vlax-invoke-method (list obj "getresponseheader" h)))
(cons h (if (not (vl-catch-all-error-p r)) (progn r)))
)
(list Headers)
)
)
)
)
)
(vlax-release-object obj)
(if (and RtnVar (not (vl-catch-all-error-p RtnVar))) ;不是错误
(cdar RtnVar)
)
)
)
)
;根据分隔符拆分字符串@LeeMac
(defun K:STR->Lst (STR Del / len Lst pos)
(setq len (1+ (strlen Del)))
(while (setq pos (vl-string-search Del STR))
(setq Lst (cons (substr STR 1 pos) Lst)
STR (substr STR (+ pos len))
)
)
(reverse (cons STR Lst))
)
;格式化获取到的网络时间OriSTR
(defun K:FmtWebTime (OriSTR / STRLst Wek Date Moth Year CurTim)
(if (and OriSTR (setq STRLst (K:STR->Lst OriSTR " ")))
(progn
(setq Wek (strcase (substr (nth 0 STRLst) 1 3)));只要前三个字母
(setq Date (nth 1 STRLst)
Moth (strcase (nth 2 STRLst))
Year (nth 3 STRLst)
)
(setq CurTim (nth 4 STRLst));当前时间
(setq Moth
(cdr
(assoc Moth
(list
(cons "JAN" "01")
(cons "FEB" "02")
(cons "MAR" "03")
(cons "APR" "04")
(cons "MAY" "05")
(cons "JUN" "06")
(cons "JUL" "07")
(cons "AUG" "08")
(cons "SEP" "09")
(cons "OCT" "10")
(cons "NOV" "11")
(cons "DEC" "12")
)
)
)
);几月份
(setq Wek
(cdr
(assoc Wek
(list (cons "MON" "01")
(cons "TUE" "02")
(cons "WED" "03")
(cons "THU" "04")
(cons "FRI" "05")
(cons "SAT" "06")
(cons "SUN" "07")
)
)
)
);周几
)
)
(if OriSTR (progn (strcat Year Moth Date)));输出年月日
)
页:
[1]