乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 93|回复: 15

[编程交流] Date format (i.e. 23DEC14)

[复制链接]

78

主题

207

帖子

129

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
395
发表于 2022-7-5 20:26:09 | 显示全部楼层 |阅读模式
So I know how to get the date from autocad using CDATE.  And I know how to parse that info to get 12/23/14.  But how can I, for example, get the 12 to be "DEC".  Do I need to make a multiple if statement for that part of the string?
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:30:17 | 显示全部楼层
 
you can use..
(cond (1 "JAN")(2 "FEB")....)
 
my example using mapcar
  1. (defun mth ( m / i l);hanhphuc 24/12/2014(setq i 13 )(eval  (cons 'cond (mapcar '(lambda (a b /) (list (eval (cons '= (list m 'a))) b))         (repeat 12 (setq l (cons (setq i (1- i)) l)))         '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEPT" "OCT" "NOV" "DEC")         ) ;_ end of mapcar ) ;_ end of cons  ) ;_ end of eval)
functional call:
 
(mth 12) ; returns "DEC"
 
since you know coding, so the rest try it yourself using string function
strcat , substr , vl-string-search
etc..
 
p/s: i'm ibanez fan  merry X'mas donate to CADtutor
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 20:34:34 | 显示全部楼层
guitarguy1685,
 
Alternatively, simply create an assoc list like so:
 
  1. (setq month '((1 . "JAN")(2 . "FEB")(3 . "MAR")(4 . "APR")      (5 . "MAY")(6 . "JUN")(7 . "JUL")(8 . "AUG")      (9 . "SEP")(10 . "OCT")(11 . "NOV")(12 . "DEC")))
 
Now whenever you need the month just issue:
 
(cdr (assoc 3 month)) will return "MAR" etc.
 
ymg
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:39:37 | 显示全部楼层
1+
 
season greetings:
ymg, i'd like to take this opportunity to credit some of your sub-functions i used in this forum.
thank you
 
merry X'mas
hanhphuc
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 20:45:23 | 显示全部楼层
hanhphuc,
 
Season's greeting ! to you too
and all the best.
 
ymg
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 20:48:30 | 显示全部楼层
Another ,
 
  1. (nth (1- 12) '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC"))
回复

使用道具 举报

26

主题

145

帖子

122

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
130
发表于 2022-7-5 20:53:35 | 显示全部楼层
;;date-->cdate
;;;;http://bbs.mjtd.com/thread-112484-1-1.html
  1. (defun Date->CDate (date / s) (setq s (strcat "M=$(edtime," (rtos date 2  ",YYYYMODD.HHMMSS)")) (atof (menucmd s))) ;defun
 
;;cdate-->date
;;;;http://bbs.mjtd.com/thread-112484-1-1.html
  1. (defun CDate->Date (cdate / Round Time Diff cd dt i0 i n s) (defun Round (x)   (if        (>= x 0)     (fix (+ x 0.5))     (fix (- x 0.5))   ) ;if ) ;defun (defun Time (dt / x h m s)   (setq x (Round (rem (* dt 1E6) 1E6)))   (setq h (/ x 10000)         m (/ (rem x 10000) 100)         s (rem x 100)   )   (/ (+ (* 3600 h) (* 60 m) s) 8.64E4) ) ;defun  (defun Diff (cd1 cd2 / y1 y2 m1 m2 d1 d2 n)   (cond     ((= cd1 cd2) (setq n 0))     ((setq y1        (/ cd1 10000)            m1        (rem (/ cd1 100) 100)            d1        (rem cd1 100)            y2        (/ cd2 10000)            m2        (rem (/ cd2 100) 100)            d2        (rem cd2 100)            n        (Round (+ (* 366 (- y1 y2)) (* 30.5 (- m1 m2)) (- d1 d2)))      )      (and (= n 0) (setq n nil))     )   ) ;cond   n ) ;defun  (setq        cd (fix cdate)       dt -47130101       i0 0       n  0 ) (while (and (setq i (Diff cd dt)) (/= i 0) (/= 0 (+ i i0)))   (setq n  (+ n i)         s  (strcat "M=$(edtime," (itoa n) ",YYYYMODD)")         dt (atoi (menucmd s))         i0 i   ) ) ;while (if (or (not i) (= 0 (+ i i0)))   (setq n nil) ) ;if (and n (setq n (+ n (Time cdate)))) n) ;defun
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:54:56 | 显示全部楼层
 
Thanks Tharwat.
simple & clean
 
This similar but it index nth in a string
  1. (menucmd (strcat "M=$(index, "         (itoa (1- i)) ; i= integer         " ,"JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEPT,OCT,NOV,DEC")"         ) )
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 21:01:27 | 显示全部楼层
 
You are welcome anytime
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-5 21:03:54 | 显示全部楼层
 
That would be (1- n)
 
Be mindful of the index number, or  (0-11)
 
nth 0 is the first element, it might confused the OP.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-11 09:14 , Processed in 0.359361 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表