Help us understand the problem. What is going on with this article?

Node.jsとDynamoDBで日時データの処理

DynamoDBに日時データを持たせる2つの方法

  1. データ型をStringにして2016-02-152015-12-21T17:42:34Zのように文字列で持たせる。
  2. データ型をNumberにして1579740176030のように数値で持たせる。

2.項のNumber型の実用例としては、エポック時間 (1970 年 1 月 1 日の 00:00:00 UTC 以降の秒数) を利用することができる。(UNIXTIMEの詳細)

Node.jsでエポック時間を扱う

現在の日時をDateオブジェクトで取得する

const date = new Date();
console.log(date);   // 2020-01-23T01:09:41.444Z
console.log(typeof date);    // 'object'

現在の日時をエポック時間で取得する

const date = Date.now();
console.log(date);   // 1579740176030
console.log(typeof date);    // 'number'

DynamoDBから取得したエポック時間をDateオブジェクトへ変換する

const unixtime = 1579740176030;  // DynamoDBから取得したエポック時間と想定
const date = new Date(unixtime);
console.log(date);   // 2020-01-23T01:09:41.444Z
console.log(typeof date);    // 'object'
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした