Mercurial > public > lazybear
comparison LazyBear/Global functions/ConvertEpoch.swift @ 321:8f8d5ad3dfa0
Preparing backend requests
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 28 Mar 2021 20:54:58 +0200 |
parents | |
children | c804ce7a1560 |
comparison
equal
deleted
inserted
replaced
320:e828c2b0764c | 321:8f8d5ad3dfa0 |
---|---|
1 // | |
2 // ConvertEpoch.swift | |
3 // LazyBear | |
4 // | |
5 // Created by Dennis Concepción Martín on 28/3/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 // Convert Epoch time to human date | |
11 func convertEpoch(_ miliseconds: Int) -> String { | |
12 let now = Date() // Current date | |
13 // TimeInterval() function must be in seconds, not in miliseconds | |
14 let articlePublished = Date(timeIntervalSince1970: TimeInterval(miliseconds/1000)) | |
15 let formatter = DateComponentsFormatter() | |
16 formatter.unitsStyle = .abbreviated | |
17 let humanDate = formatter.string(from: articlePublished, to: now)! | |
18 | |
19 return humanDate | |
20 } |