Cassandra、MySQL 和 Flutter 中可使用的一般时间值是什么?

huangapple go评论69阅读模式
英文:

What is the general time value that I can use in Cassandra, MySQL and Flutter?

问题

I am using created_at TIMESTAMP in my Cassandra schema and have the following code in my NodeJS app:

在我的Cassandra架构中,我正在使用created_at TIMESTAMP,并且在我的NodeJS应用程序中有以下代码:

INSERT INTO books (id, user_id, created_at)
VALUES (uuid(), 'userOne', toTimestamp(now()));

我喜欢知道,如果我在我的mysql应用程序中使用 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 并在我的Flutter应用程序中使用 DateTime.now().millisecondsSinceEpoch,这些TIMESTAMP值是否会匹配在一起?如果不匹配,我可以使用什么?

我想知道,如果我在MySQL应用程序中使用created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,并在Flutter应用程序中使用DateTime.now().millisecondsSinceEpoch,这些TIMESTAMP值是否会匹配?如果不匹配,我可以使用什么?

In summary, if I use:

总之,如果我使用以下内容:

@MySQL Schema:

@MySQL架构:

created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

@Cassandra Schema and command:

@Cassandra架构和命令:

//at the Schema
//在架构中
created_at TIMESTAMP
//inside the NodeJS code
//在NodeJS代码中
INSERT INTO table_name (created_at)
VALUES (toTimestamp(now()));

@Flutter code:

@Flutter代码:

String timestamp = DateTime.now().millisecondsSinceEpoch.toString();

They all should be same and compatible?

它们应该是相同且兼容的吗?

英文:

I am using created_at TIMESTAMP in my Cassandra schema and have the following code in my NodeJS app:

INSERT INTO books (id, user_id, created_at)
VALUES (uuid(), 'userOne', toTimestamp(now()));

I like to know, if I am using created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP in my mysql app and DateTime.now().millisecondsSinceEpoch in my Flutter application, will these TIMESTAMP values all match together? If not, what can I use for all of them?

In summary, if I use:

@MySQL Schema:

  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

@Cassandra Schema and command:

//at the Schema
created_at TIMESTAMP
//inside the NodeJS code
INSERT INTO table_name (created_at)
VALUES (toTimestamp(now()));

@Flutter code:

String timestamp = DateTime.now().millisecondsSinceEpoch.toString();

They all should be same and compatible?

答案1

得分: 1

CQL中的timestamp数据类型是一个64位有符号整数,表示自Unix纪元以来的毫秒数。另一方面,CQL的timeuuid是一个版本1的UUID,即包含时间戳的UUID。

CQL中的now()函数以timeuuid格式返回系统时间,等同于currentTimeUuid()函数。当now()嵌套在toTimestamp()中时,它以timestamp格式返回系统时间。

CQL中的timestamp类型支持整数和字符串。

MySQL将时间戳值转换为UTC。当使用MySQL时间戳值(字符串形式)设置CQL timestamp列时,必须符合ISO-8601标准。有效的格式包括:

  • yyyy-mm-dd(仅日期)
  • yyyy-mm-dd hh:MM:ss(日期和时间)
  • yyyy-mm-dd hh:MM:ss.fff(带有毫秒精度的时间)
  • yyyy-mm-dd hh:MM:ss.fff [+/-]NNNN(带有RFC 822 4位数字时区的时间,例如+0000表示GMT或+1000表示墨尔本)

Flutter中的DateTime.now().millisecondsSinceEpoch()返回一个整数,因此也与CQL的timestamp类型兼容。祝好!

英文:

The CQL timestamp data type is a 64-bit signed integer that represents the number of milliseconds since Unix epoch. On the other hand, the CQL timeuuid is a version 1 UUID, i.e. a UUID with a timestamp included.

The CQL now() returns the system time in timeuuid format and is equivalent to the currentTimeUuid() function. When now() is nested in toTimestamp(), it returns the system time in timestamp format.

The CQL timestamp type supports BOTH integers and strings.

MySQL converts timestamp values into UTC. When setting CQL timestamp columns using MySQL timestamp values as string, it must conform to ISO-8601. The valid formats are:

  • yyyy-mm-dd (date only)
  • yyyy-mm-dd hh:MM:ss (date with time)
  • yyyy-mm-dd hh:MM:ss.fff (with time in millisecond precision)
  • yyyy-mm-dd hh:MM:ss.fff [+/-]NNNN (with RFC 822 4-digit optional timezone, e.g. +0000 for GMT or +1000 for Melbourne)

The Flutter DateTime.now().millisecondsSinceEpoch() returns an integer so it is also compatible with CQL timestamp type. Cheers!

huangapple
  • 本文由 发表于 2023年2月6日 12:59:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75357457.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定