javascript - Groovy 呈现为 JSON java.sql.timestamp 在 JavaScript 中不显示毫秒数

标签 javascript json grails timestamp

我有一个 java.util.ArrayList,其中包含红色标记的值:enter image description here

如果我使用 render relations as JSON 渲染它,那么在 JavaScript 中,值如下: enter image description here

毫秒消失了,如果我没理解错的话,receiveDate 的值是一个字符串,因此无法将其解析为另一种格式。

有没有办法渲染出毫秒数没有消失的值?

最佳答案

方法一

import grails.converters.JSON

def r = [now: new Date(), name: 'Roong']
JSON.registerObjectMarshaller(Date) {o -> o.getTime()}
println(r as JSON)

结果 1

{
  "now": 1356595418027,
  "name": "Roong"
}

或者你可以在Config.groovy中设置
方法二

grails.converters.json.date = "javascript"

结果 2

{
  "now": new Date(1356595418027),
  "name": "Roong"
}

关于javascript - Groovy 呈现为 JSON java.sql.timestamp 在 JavaScript 中不显示毫秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14031548/

相关文章:

php - json_encode bool 返回错误值

grails - 建立 war 时删除插件 View (gsp)

html - 将 GSP View 呈现为紧凑的 html 文件

javascript - 将 SVG 下载为 PNG 图像

javascript - 通过跳过分割字符在 JavaScript 中分割字符串

javascript - 使用 Javascript 过滤文本框中的文本

python - 如何使用python将数据转储到Json文件中

javascript - react : Asynchronous call to update state before final render method is called

mongodb - 安装mongeez插件时出现错误

javascript - 如何让动画在视口(viewport)中启动一次