0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftでUNIX時間をDate型へ変換する

Posted at

ググってすぐに出てこなかったので備忘録です。
dynamodbへ文字列でUNIX時間を保存し、swiftでdate型で扱う必要があったので。

#UNIX時間で保存し、swiftで日時として扱う

let str = "1552273063375"
var int64 = Int64(str) ?? 0
int64 = int64 / 1000
let timeIterval = TimeInterval(integerLiteral: int64)
let day = Date(timeIntervalSince1970: timeIterval)

dynamoDBへ文字列で保存してしまっているので、
int64 > timeInterval > date
と変換しています。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?