Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Global functions/ConvertEpoch.swift Sun Mar 28 20:54:58 2021 +0200 @@ -0,0 +1,20 @@ +// +// ConvertEpoch.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 28/3/21. +// + +import SwiftUI + +// Convert Epoch time to human date +func convertEpoch(_ miliseconds: Int) -> String { + let now = Date() // Current date + // TimeInterval() function must be in seconds, not in miliseconds + let articlePublished = Date(timeIntervalSince1970: TimeInterval(miliseconds/1000)) + let formatter = DateComponentsFormatter() + formatter.unitsStyle = .abbreviated + let humanDate = formatter.string(from: articlePublished, to: now)! + + return humanDate +}