💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# date 日期格式化标签 ## 日期格式化标签 格式化日期时间 ## 格式 $Info\['publish\_time'\] 文章发布时间 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>date name<span class="token">=</span><span class="token4">"$Info['publish_time']"</span> format<span class="token">=</span><span class="token4">"Y-m-d H:i:s"</span><span class="token1">}</span> ``` ``` ## 参数 参数名称可选值默认值是否必填支持版本说明name--是-待转换的值,传入变量或指定日期format-Y-m-d--格式api--->=v2.2.1.20220603详情看下面lt--->=v2.2.1.20220603小于多少秒format 日期与时间格式参数说明 - d - 表示月里的某天(01-31) - m - 表示月(01-12) - Y - 表示年(四位数) - l - 表示周里的某天 - h - 带有首位零的 12 小时小时格式 - H - 24小时格式 - i - 带有首位零的分钟 - s - 带有首位零的秒(00 -59) - a - 小写的午前和午后(am 或 pm) ## 示例 - 内容标签里面对内容发布日期格式化 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>content catid<span class="token">=</span><span class="token4">"10"</span> order<span class="token">=</span><span class="token4">"weigh desc,views desc"</span> num<span class="token">=</span><span class="token4">"$Cate['num']"</span><span class="token1">}</span> <span class="token"><</span>span class<span class="token">=</span><span class="token4">"date"</span><span class="token">></span><span class="token1">{</span>hkcms<span class="token1">:</span>date name<span class="token">=</span><span class="token4">"$item.publish_time"</span> format<span class="token">=</span><span class="token4">"Y-m-d"</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>span<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>content<span class="token1">}</span> ``` ``` - 语义化日期,例如:**3小时前,1个月前,56秒前**,刚刚。( >=v2.2.1.20220603) `api="human"` 将采用日期语义化显示 ``` <pre class="calibre16">``` <span class="token5">//,lt="2592000" 单位秒, 表示超过一个月的按format里面的格式输出,如果不需要那直接只写api="human"即可</span> <span class="token"><</span>span class<span class="token">=</span><span class="token4">"date"</span><span class="token">></span><span class="token1">{</span>hkcms<span class="token1">:</span>date name<span class="token">=</span><span class="token4">"$item.publish_time"</span> format<span class="token">=</span><span class="token4">"Y-m-d"</span> api<span class="token">=</span><span class="token4">"human"</span> lt<span class="token">=</span><span class="token4">"2592000"</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>span<span class="token">></span> ``` ``` 全部语义化 ``` <pre class="calibre16">``` <span class="token"><</span>span class<span class="token">=</span><span class="token4">"date"</span><span class="token">></span><span class="token1">{</span>hkcms<span class="token1">:</span>date name<span class="token">=</span><span class="token4">"$item.publish_time"</span> api<span class="token">=</span><span class="token4">"human"</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>span<span class="token">></span> ``` ``` - 时间戳(1601528401)转化成格式2020-10-01 13:00:01 ``` <pre class="calibre16">``` <span class="token5">// name 可以传入变量</span> <span class="token1">{</span>hkcms<span class="token1">:</span>date name<span class="token">=</span><span class="token4">"$item.create_time"</span> format<span class="token">=</span><span class="token4">"Y-m-d H:i:s"</span><span class="token1">}</span> ``` ``` - 将日期2020-10-01 13:00:01,转换成2020年10月01日 ``` <pre class="calibre20">``` <span class="token"><</span><span class="token">?</span>php $d <span class="token">=</span> <span class="token4">'2020-10-01 13:00:01'</span><span class="token1">;</span><span class="token">?</span><span class="token">></span> <span class="token5">// 传入变量</span> <span class="token1">{</span>hkcms<span class="token1">:</span>date name<span class="token">=</span><span class="token4">"$d"</span> format<span class="token">=</span><span class="token4">"Y年m月d日"</span><span class="token1">}</span> ``` ```