javascript - 将 Javascript 中的当前时间传递给 GraphQL AWSDateTime 列
问题描述
我有一个带有类型Channel
列的 GraphQL 表dateOn
AWSDateTime
在我的 React 应用程序中,我调用了一个突变来创建一个新的Channel
. 以下是相关代码:
const createChannel = `
mutation createChannel {
createChannel(input:{
title:"${title}"
dateOn:${Date.now()}
slug: "${slug}"
authorId: "${authorId}"
}) {
id title slug authorId
}
}
`;
AWS 接受以下格式的日期时间字符串:
The AWSDateTime scalar type represents a valid extended ISO 8601 DateTime string. In other words, this scalar type accepts datetime strings of the form YYYY-MM-DDThh:mm:ss.sssZ
我将如何在 Javascript 中以这种格式传递当前时间?
解决方案
你可以用直接的 javascript 来做到这一点new Date().toISOString()
。然而,这应该由后端的解析器处理,而不是从前端传递值。
同样 moment.js 是一个很大的依赖项,除非您打算广泛使用它,否则我会使用类似date-fns
.
推荐阅读
- powershell - 在詹金斯中将密码绑定传递给PowerShell脚本时遇到问题
- sql - 旋转多个属性并将它们分组为“单个”属性(多对一)
- php - PHP获取星期几的日期
- javascript - axios 拦截器:自定义标头仅添加到 OPTIONS 请求中
- sql - 最后第二行代码中出现错误,错误为 00933。00000 -“SQL 命令未正确结束”。如何解决这个问题?
- javascript - 带有编辑选项的画布图像
- vue.js - 在 x-template 中获取 Vue.js 实例特定的组件数据
- spring-boot - org.thymeleaf.exceptions.TemplateProcessingException
- codeigniter - Codeigniter 3 验证错误未与回调函数一起显示
- tensorflow - 如何在 Arch linux 中降级到 cuda 10.0?