icu_date给出错误消息尝试索引数字值

问题描述

我想使用icu_date库,但是当我尝试插入值时,出现错误

icu_date = require("icu-date")
format_date = icu_date.formats.iso8601()
end_time = icu_date.Now()
1602586287098 - print value
end_time:set_millis(1602461532000)
error: '[string "return end_time:set_millis(1602461532000)"]:1: attempt to index global ''end_time'' (a number value)'

也许没有足够的库?

  • 库libicu-devel-50.2-4.el7_7.x86_64
  • 系统:Centos 7

解决方法

似乎您需要使用icu_date.new()(而不是now)来创建新实例。然后,您可以按照自己的方式使用它:

icu_date = require("icu-date")
format_date = icu_date.formats.iso8601()
end_time = icu_date.new()
end_time:set_millis(1602461532000)
tarantool> end_time:format(format_date)
---
- 2020-10-12T00:12:12.000Z
...

icu_date.now()返回当前时间。这实际上是一个数字值。

tarantool> icu_date = require('icu-date')
---
...

tarantool> icu_date.now()
---
- 1602597687320
...