Created
December 28, 2016 16:36
-
-
Save fbukevin/646da5db139664b172fad788c5a49403 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class TimeTool { | |
func getCurrentTimeString() -> String { | |
let now = Date() | |
let df = DateFormatter() | |
df.dateFormat = "YYYY/MM/dd HH:mm:ss" | |
return df.string(from: now) | |
} | |
func dateToString(date: Date) -> String { | |
let cal = Calendar.current | |
let yr = cal.component(.year, from: date) | |
let mth = cal.component(.month, from: date) | |
let day = cal.component(.day, from: date) | |
let hr = cal.component(.hour, from: date) | |
let min = cal.component(.minute, from: date) | |
let sec = cal.component(.second, from: date) | |
let dateString = "\(yr)/\(mth)/\(day) \(hr):\(min):\(sec)" | |
return dateString | |
} | |
func stringToDate(date: String) -> Date { | |
let df = DateFormatter() | |
df.dateFormat = "YYYY/MM/dd HH:mm:ss" | |
return df.date(from: date)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment