我从 Blogger 获得的以下输出中有一个日期格式:
<time class="published">14 March</time>
我想在不修改输出的情况下更改其格式,如下所示:
<time class="published"><span class="day">14</span><span class="month">Mar</span></time>
有人有什么建议吗?
最佳答案
更新
当您使用新主题时,更改日期格式时间戳的过程会略有不同。添加以下内容b:includable
进入b:widget
您想要更改时间戳的位置 -
<b:includable id='postTimestamp'>
<span class='byline post-timestamp'>
<data:byline.label />
<b:if cond='data:post.url'>
<meta expr:content='data:post.url.canonical' />
<a class='timestamp-link' expr:href='data:post.url' rel='bookmark' title='permanent link'>
<time class='published' expr:datetime='data:post.date.iso8601' expr:title='data:post.date.iso8601'>
<b:eval expr='data:post.date format "dd MMM" '/>
</time>
</a>
</b:if>
</span>
</b:includable>
您会注意到,日期的格式通过新引入的 format
进行了更改。运算符(operator)。有关 format
的详细文档运算符-
format(date, format)
Formats the given date to the given format string, using the blog's selected language.
date: Date to be formatted, e.g. data:post.date
format: ICU format string for the date to be formatted to, in the blog's language. e.g. "MMM dd".
<b:eval expr='data:post.date format "MMM dd" ' />
目前官方文档还没有新的主题,我引用了Blogger engineer's blog获取此信息。
<小时/>要实现此目的,必须通过 JavaScript 操作日期。在主题代码中,您将看到类似的代码 -
<time class="published"><data:post.timestamp/></time>
将其替换为 -
<time class="published"><script>dateconvert(new Date('<data:post.timestamp/>'));</script></time>
并定义dateconvert
</head>
内的函数 block -
<script>
function dateconvert(date) {
document.write("<span class='day'>" + date.getDate() + "</span> <span class='month'>" + date.toLocaleString("en-us", {month: "short"}) + '</span>')
}
</script>
关于javascript - 设置发布日期格式并添加类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43602187/