首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AutoLISP获取UTC DateTime

使用AutoLISP获取UTC DateTime
EN

Stack Overflow用户
提问于 2017-03-27 10:50:17
回答 2查看 481关注 0票数 0

在AutoLISP中,我找到了两种调用date CDATEDATE的方法。但是,我需要获取UTC日期时间。我一直在搜索它的函数,但是没有找到。

有没有办法获取UTC日期时间?

是否可以手动从当前时间减去或添加到当前时间?

非常感谢!

EN

回答 2

Stack Overflow用户

发布于 2018-01-07 19:35:44

您可以使用以下函数从NIST Internet时间服务器检索UTC日期时间:

代码语言:javascript
复制
;; Internet Time  -  Lee Mac
;; Returns the date and/or UTC time as a string in the format specified.
;; Data is sourced from a NIST Internet Time Server.
;; 
;; The format argument may use the following identifiers to represent date & time quantities:
;; YYYY = 4-digit year
;; YY   = Year
;; MO   = Month
;; DD   = Day
;; HH   = Hour
;; MM   = Minutes
;; SS   = Seconds

(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)
                            (setq str (strcat " " (itoa (jtoy (+ (atoi (substr str 2 5)) 2400000.5))) (substr str 7)))
                            (mapcar
                                (function
                                    (lambda ( a b )
                                        (vlax-put-property rgx 'pattern a)
                                        (setq format (vlax-invoke rgx 'replace format b))
                                    )
                                )
                               '("YYYY" "YY" "MO" "DD" "HH" "MM" "SS")
                               '( "$1"  "$2" "$3" "$4" "$5" "$6" "$7")
                            )
                            (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)
)

;; Julian Date to Calendar Year
;; Algorithm from: Meeus, Jean.  Astronomical Algorithms.

(defun jtoy ( j / a b c d )
    (setq j (fix j)
          a (fix (/ (- j 1867216.25) 36524.25))
          b (+ (- (+ j 1 a) (fix (/ a 4))) 1524)
          c (fix (/ (- b 122.1) 365.25))
          d (fix (/ (- b (fix (* 365.25 c))) 30.6001))
    )
    (fix (- c (if (< 2 (fix (if (< d 14) (1- d) (- d 13)))) 4716 4715)))
)

下面是一个示例:

代码语言:javascript
复制
_$ (LM:internettime "YYYY-MO-DD HH:MM:SS")
"2018-01-07 11:34:24"
票数 1
EN

Stack Overflow用户

发布于 2017-04-20 10:26:05

您可以使用vlax-create-object调用PowerShell来执行:(Get-Date).ToUniversalTime()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43037201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档