How to store a timestamp (ms since 1970)

I feel pretty stupid asking this question because I can’t imagine that I myself couldn’t understand.

In my application, I need to work with the timestamp that I get through JSON from my server. Since 1970 is a long time ago, this is a fairly large number - for example, 1.410.882.267.548. Actually huge to store it in int (max. 2,147,483,647).

However, it seems that there is no long or other “larger” data type in swift - so how do I store it to work with it?

+1
swift
source share
1 answer

It seems that Int and UInt can hold this value.

Your number: 1_410_882_267_548 Int.max: 9_223_372_036_854_775_807 UInt.max: 18_446_744_073_709_551_615 

This value may occur in other languages, but Swift offers a fairly large maximum value for Int and UInt. I don’t think this max can cause timestamp problems at any time.

+1
source share

All Articles