- 积分
- 12307
- 明经币
- 个
- 注册时间
- 2004-2-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2022-5-31 15:27:58
|
显示全部楼层
- ;;---------------------=={ Internet Time }==------------------;;
- ;; ;;
- ;; Returns the date and/or UTC time as a string in the ;;
- ;; format specified. Data is sourced from a NIST server. ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: ;;
- ;; format - string specifying format of returned information ;;
- ;; using the following identifiers to represent ;;
- ;; date & time quantities: ;;
- ;; YY = Year, MO = Month, DD = Day ;;
- ;; HH = Hour, MM = Minutes, SS = Seconds ;;
- ;;------------------------------------------------------------;;
- ;; Returns: String containing formatted date/time data ;;
- ;;------------------------------------------------------------;;
- (defun LM:InternetTime ( format / result rgx server xml )
- (setq server "http://time.nist.gov:13")
- (setq result
- (vl-catch-all-apply
- (function
- (lambda ( / str )
- (setq xml (vlax-create-object "MSXML2.XMLHTTP.3.0"))
- (setq rgx (vlax-create-object "VBScript.RegExp"))
- (vlax-invoke-method xml 'open "POST" server :vlax-false)
- (vlax-invoke-method xml 'send)
- (if (setq str (vlax-get-property xml 'responsetext))
- (progn
- (vlax-put-property rgx 'global actrue)
- (vlax-put-property rgx 'ignorecase actrue)
- (vlax-put-property rgx 'multiline actrue)
- (mapcar
- (function
- (lambda ( a b )
- (vlax-put-property rgx 'pattern a)
- (setq format (vlax-invoke rgx 'replace format b))
- )
- )
- '("YY" "MO" "DD" "HH" "MM" "SS")
- '("$1" "$2" "$3" "$4" "$5" "$6")
- )
- (vlax-put-property rgx 'pattern
- (strcat
- "(?:[^\\d]+[\\d]+[^\\d]+)"
- "([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)"
- "([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)([\\d]+)(?:.+)\\n"
- )
- )
- (vlax-invoke-method rgx 'replace str format)
- )
- )
- )
- )
- )
- )
- (if xml (vlax-release-object xml))
- (if rgx (vlax-release-object rgx))
- (if (not (vl-catch-all-error-p result))
- result
- )
- )
The 'format' parameter
This parameter is a string specifying the format for the returned data. It is used in a similar way to the 'picture' parameter for the edtime DIESEL function, using the following identifiers to represent date & time quantities:
Code: [Select]
YY = Year
MO = Month
DD = Day
HH = Hours
MM = Minutes
SS = Seconds
Examples
Code: [Select]
_$ (LM:InternetTime "DD/MO/YY, HH:MM:SS")
"17/09/11, 19:37:07"
Code: [Select]
_$ (LM:InternetTime "MO.DD.YY")
"09.17.11"
Code: [Select]
_$ (LM:InternetTime "HH:MM")
"19:37"
|
|