Gatsby GraphQL 自定义日期格式字符串
Gatsby GraphQL custom date formatString
我有这个:
export const pageQuery = graphql`
query {
site {
siteMetadata {
title
}
}
allMdx(sort: { fields: [frontmatter___date], order: DESC }) {
edges {
node {
excerpt
fields {
slug
}
frontmatter {
date(formatString: "DD 'de' MMMM, YYYY", locale: "pt")
title
description
}
}
}
}
}
`
在行中>>
date(formatString: "DD 'de' MMMM, YYYY", locale: "pt")
我必须插入字符串,但是这个 'de' 不起作用。我知道我想显示这样的日期:
25 de March, 2020.
但结果是:
25 '32' March, 2020.
我知道这行不通,我知道为什么,但我做不到。
我将 Gatsbyjs 与 graphql
结合使用
盖茨比依赖moment.js to format dates。
To escape characters in format strings, you can wrap the custom string in square brackets.
date(formatString: "DD [de] MMMM, YYYY", locale: "pt")
简单点
日期(formatString: "DD MMMM, YYYY")
Output Like this: 04 February, 2021
我有这个:
export const pageQuery = graphql`
query {
site {
siteMetadata {
title
}
}
allMdx(sort: { fields: [frontmatter___date], order: DESC }) {
edges {
node {
excerpt
fields {
slug
}
frontmatter {
date(formatString: "DD 'de' MMMM, YYYY", locale: "pt")
title
description
}
}
}
}
}
`
在行中>>
date(formatString: "DD 'de' MMMM, YYYY", locale: "pt")
我必须插入字符串,但是这个 'de' 不起作用。我知道我想显示这样的日期:
25 de March, 2020.
但结果是:
25 '32' March, 2020.
我知道这行不通,我知道为什么,但我做不到。
我将 Gatsbyjs 与 graphql
盖茨比依赖moment.js to format dates。
To escape characters in format strings, you can wrap the custom string in square brackets.
date(formatString: "DD [de] MMMM, YYYY", locale: "pt")
简单点
日期(formatString: "DD MMMM, YYYY")
Output Like this: 04 February, 2021