在帖子的开头,我使用以下日期格式:
---
date: 2020-10-23T01:11:32+03:00
---
在查询中,我使用以下格式:
frontmatter {
date(formatString: "DD.MM.YYYY HH:mm:ss")
}
我希望23.10.2020 01:11:32
,但得到22.10.2020 22:11:32
。
如何获得23.10.2020 01:11:32
?
加法1
此标记:
<time className="post-date"><small>{post.frontmatter.date}</small></time>
此查询:
export const pageQuery = graphql`
query {
site {
siteMetadata {
lang
author
description
keywords
title
siteUrl
}
}
allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
nodes {
excerpt
fields {
slug
}
frontmatter {
title
date(formatString: "DD.MM.YYYY HH:mm:ss")
description
}
}
}
}
`
答案 0 :(得分:0)
您有多种方法可以绕过它。
最原生的尝试在locale
过滤器中使用formatString
:
frontmatter {
date(formatString: "DD.MM.YYYY HH:mm:ss", locale:"en") // en by default, change it to what you need
}
formatString
使用momentjs
提供的选项,检查their documentation中的更多语言环境和过滤器。
如果以前的方法不符合您的规范,则可以始终在JavaScript文件中处理结果,例如:
const date= props.data.allMarkdownRemark.nodes[0].frontmatter.date;
date.format('llll'); // will outpout something like Tue, Oct 27, 2020 7:27 AM
免责声明:请注意,到达日期的路径是伪造的,是伪造的,请寻求解决方法,没有路径。