date将秒数转换成日期的字符串表达形式

这里要用到date函数的第三种形式,下面是获得当前日期

(set 'today (date (date-value) 0 "%Y%m%d"))

(date-value) 返回的是1970年0点累计的秒数,作为date函数的第一个参数

第二个参数是偏移的分钟,0表示没有偏移,就是当前时区的现在时间。 这个参数很有用,可以计算昨天的时间,也可以计算其他时区的时间

第三个参数定义日期格式,参考下表:

formatdescription
%aabbreviated weekday name according to the current locale
%Afull weekday name according to the current locale
%babbreviated month name according to the current locale
%Bfull month name according to the current locale
%cpreferred date and time representation for the current locale
%dday of the month as a decimal number (range 01–31)
%Hhour as a decimal number using a 24-hour clock (range 00–23)
%Ihour as a decimal number using a 12-hour clock (range 01–12)
%jday of the year as a decimal number (range 001–366)
%mmonth as a decimal number (range 01–12)
%Mminute as a decimal number
%peither 'am' or 'pm' according to the given time value or the corresponding strings for the current locale
%Ssecond as a decimal number 0–61 (60 and 61 to account for occasional leap seconds)
%Uweek number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
%wday of the week as a decimal, Sunday being 0
%Wweek number of the current year as a decimal number, starting with the first Monday as the first day of the first week
%xpreferred date representation for the current locale without the time
%Xpreferred time representation for the current locale without the date
%yyear as a decimal number without a century (range 00–99)
%Yyear as a decimal number including the century
%ztime zone or name or abbreviation (same as %Z on Win32, different on Unix)
%Ztime zone or name or abbreviation (same as %z on Win32, different on Unix)
%%a literal '%' character

下面是使用了偏移参数计算昨天的日期:

(set 'yesterday (date (date-value) (- (* 24 60)) "%Y%m%d"))

24小时乘以60分钟,结果加上负号



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值