首页 > 代码库 > 获取当前日期
获取当前日期
这里要用到date函数的第三种形式,下面是获得当前日期
(set ‘today (date (date-value) 0 "%Y%m%d"))
(date-value) 返回的是1970年0点累计的秒数,作为date函数的第一个参数
第二个参数是偏移的分钟,0表示没有偏移,就是现在。 这个参数主要用来做时区转换
第三个参数定义日期格式,参考下表:
format | description |
---|---|
%a | abbreviated weekday name according to the current locale |
%A | full weekday name according to the current locale |
%b | abbreviated month name according to the current locale |
%B | full month name according to the current locale |
%c | preferred date and time representation for the current locale |
%d | day of the month as a decimal number (range 01–31) |
%H | hour as a decimal number using a 24-hour clock (range 00–23) |
%I | hour as a decimal number using a 12-hour clock (range 01–12) |
%j | day of the year as a decimal number (range 001–366) |
%m | month as a decimal number (range 01–12) |
%M | minute as a decimal number |
%p | either ‘am‘ or ‘pm‘ according to the given time value or the corresponding strings for the current locale |
%S | second as a decimal number 0–61 (60 and 61 to account for occasional leap seconds) |
%U | week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week |
%w | day of the week as a decimal, Sunday being 0 |
%W | week number of the current year as a decimal number, starting with the first Monday as the first day of the first week |
%x | preferred date representation for the current locale without the time |
%X | preferred time representation for the current locale without the date |
%y | year as a decimal number without a century (range 00–99) |
%Y | year as a decimal number including the century |
%z | time zone or name or abbreviation (same as %Z on Win32, different on Unix) |
%Z | time 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分钟,结果加上负号
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。