明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 920|回复: 9

[提问] 日期计算公式方法

[复制链接]
发表于 2018-4-14 20:25 来自手机 | 显示全部楼层 |阅读模式
各位大老师,今天在搞一个小东西时,突然遇到日期的计算,一怒一下将日期20180614-20180414结果等于200天     后来想想不对啊不应该是60天才对,求老师指点一个日期计算的方法或者公式

点评

yxp
用 5 楼的程序算了一下,是 61 天,好像五月是 31 天  发表于 2018-4-16 09:12
 楼主| 发表于 2018-4-14 20:26 来自手机 | 显示全部楼层
第一次遇到日期计算,还请老师点播
发表于 2018-4-15 08:45 来自手机 | 显示全部楼层
EXCEL里面就可以计算,还自动考虑的大小月,闰年
 楼主| 发表于 2018-4-15 23:15 来自手机 | 显示全部楼层
yxp 发表于 2018-4-15 08:45
EXCEL里面就可以计算,还自动考虑的大小月,闰年

要lisp函数,Excel计算木得用喽
发表于 2018-4-16 09:07 | 显示全部楼层
柴月二号 发表于 2018-4-15 23:15
要lisp函数,Excel计算木得用喽

既然这么说,肯定可以做到撒,就是代码啰嗦了点
  1. ;;日期格式样式: "yyyy-mm-dd"
  2. ;;示例: (test "2018-06-14" "2018-04-14")
  3. (defun test(d1 d2)
  4. (setq Gp vlax-get-property
  5.         Pp vlax-put-property
  6.         Wb (Gp (vlax-get-or-create-object "Excel.Application") 'Workbooks)
  7.         Ws (if(=(Gp Wb 'count) 0)(vlax-invoke Wb 'add)(Gp Wb 'item 1))
  8.         Wr (Gp (Gp Ws 'Worksheets) 'item 1)
  9.         dr1 (Gp Wr 'Range "A1")
  10.         dr2 (Gp Wr 'Range "A2")
  11.         dr3 (Gp Wr 'Range "A3")
  12.         pr1 (Pp dr1 'value2 d1)
  13.         pr2 (Pp dr2 'value2 d2)
  14.         dx3 (Pp dr3 'value2 "=A1-A2")
  15.         va (vlax-variant-value (Gp dr3 'value2)))
  16. )
发表于 2018-4-16 09:41 | 显示全部楼层
Ref:
;;;
;;;    JULIAN.LSP
;;;    Copyright ?1999 by Autodesk, Inc.
;;;

...

;;; DESCRIPTION
;;;
;;;         AutoCAD Julian date / calendar date conversion routines
;;;
;;; CTOJ  --  Converts calendar date and time to Julian date
;;;
;;;     Call:     (ctoj <year> <month> <day> <hour> <minute> <second/fraction>)
;;;     Input:    Calendar date as argument list, for example:
;;;                     (ctoj 1957 10 4 19 26 24) ; Launch of Sputnik 1
;;;     Returns:  Julian date / fraction, as in DATE setvar
;;;
;;;
;;; DTOJ  --  Converts AutoCAD calendar date/time to Julian date
;;;
;;;     Call:     (dtoj <calendar date>)
;;;     Input:    Real number YYYYMMDD<.HHMMSSmsec>, like CDATE setvar.
;;;     Returns:  Julian date / fraction, as in DATE setvar
;;;
;;;
;;; JTOC  --  Converts Julian date to calendar date list
;;;
;;;     Call:     (jtoc <Julian date>)
;;;     Input:    Real number <Julian day>.<fraction>, like DATE setvar
;;;     Returns:  Calendar date/time list:
;;;                 (<year> <month> <day> <hour> <minute> <second/fraction>)
;;;
;;;
;;; JTOD  --  Converts Julian date to AutoCAD calendar date/time
;;;
;;;     Call:     (jtod <Julian date>)
;;;     Input:    Real number <Julian day>.<fraction>, like DATE setvar
;;;     Returns:  Calendar date/time, as in CDATE setvar
;;;
;;;
;;; JTOW  --  Determines day of the week for a given Julian day
;;;
;;;     Call:     (jtow <Julian date>)
;;;     Input:    Real number <Julian day>.<fraction>, like DATE setvar
;;;     Returns:  Integer day of the week, 0 = Sunday, 1 = Monday, ...
;;;               6 = Saturday
;;;
;;;
;;; C:DATE  --  Implements DATE command to display the current date/time
;;;             in the format: Day YYYY/M/D HH:MM:SS.msec
;;;
;;;     Call:     DATE  (at AutoCAD's Command: prompt)
;;;     Input:    None (obtains DATE setvar in Julian format)
;;;     Returns;  Nothing
;;;
;;;     Uses (JTOD) to convert to calendar format, and edits the date/time
;;;     from there.  Day of the week is calculated with (JTOW).
;;;
;;;
;;; Note  that  a  Julian  date  returned  by AutoCAD's DATE setvar or
;;; computed from the CDATE setvar is a true Julian date only  if  the
;;; system's clock is set to UTC/Zulu  (Greenwich Mean Time).   Julian
;;; dates  are easily compared for earlier/later, and durations can be
;;; computed via simple subtraction.  However,  such calculations  are
;;; accurate  only  for  readings obtained in the same time zone, with
;;; the same clock or synchronized clocks.

发表于 2018-4-16 16:24 | 显示全部楼层
yxp 发表于 2018-4-16 09:07
既然这么说,肯定可以做到撒,就是代码啰嗦了点

可以考虑用VBS,万一没装excel呢
 楼主| 发表于 2018-4-16 22:03 来自手机 | 显示全部楼层
yxp 发表于 2018-4-16 09:07
既然这么说,肯定可以做到撒,就是代码啰嗦了点

谢谢谢谢谢谢
 楼主| 发表于 2018-4-16 22:04 来自手机 | 显示全部楼层
Andyhon 发表于 2018-4-16 09:41
Ref:
;;;
;;;    JULIAN.LSP

谢谢..................
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-25 10:19 , Processed in 0.385208 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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