123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- //
- // KMAdvertisementTimeStampConversion.swift
- // KMAdvertisement
- //
- // Created by lizhe on 2022/11/29.
- //
- public class KMAdvertisementTimeStampConversion: NSObject {
-
- /**
- @abstract 时间string转时间戳
- @param dateString 时间戳字符串
- @return 时间
- */
- static func stringDateToTimestamp(dateString: String) -> TimeInterval{
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- let date = formatter.date(from: dateString)
- let time = date!.timeIntervalSince1970 * 1000
- return time
- }
- /**
- @abstract 时间戳转换成时间(HH:mm)
- @param timeString 时间戳字符串(毫秒)
- @return 时间string
- */
- static func timeStringToTimeSecond(timeString: String) -> String {
- let interval: TimeInterval = Double(timeString)! / 1000.0
- let date: Date = Date.init(timeIntervalSince1970: interval)
- let formatter = DateFormatter()
- formatter.dateFormat = "HH:mm"
- let dateString = formatter.string(from: date)
- return dateString
- }
- /**
- @abstract 时间string转date
- @param string 时间
- @return Date 时间
- */
- static func stringChangeToDate(string: String) -> Date {
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- formatter.timeZone = NSTimeZone(abbreviation: "UTC") as TimeZone?
- return formatter.date(from: string)!
- }
- /**
- @abstract date转时间string
- @param date 时间
- @return NSString 时间
- */
- static func dateChangeToString(date: Date) -> String {
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd"
- return formatter.string(from: date)
- }
-
- /**
- @abstract 获取当前的时间string
- @return NSString 时间
- */
- public static func getCurrentCompainedDateString() -> String {
- let date: Date = NSDate() as Date
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- let timeString = formatter.string(from: date)
- return timeString
- }
-
- /**
- @abstract 获取当前时间时间戳
- */
- public static func getCurrentTimeInterval () -> String {
- let date = NSDate.init()
- let timeSp: String = String(CLong(date.timeIntervalSince1970 * 1000))
- return timeSp
- }
-
- /**
- @abstract 判断是否是24小时之内
- @param timeStamp 时间
- @return bool
- */
- static func isInaDayWithTimestamp(timeStamp: TimeInterval) -> Bool {
- let currentTimeInterval:TimeInterval = Double(KMAdvertisementTimeStampConversion.getCurrentTimeInterval())!
- if (currentTimeInterval - timeStamp < 24 * 60 * 60) {
- return true
- } else {
- return false
- }
- }
- /**
- @abstract 获取当前的时间(年月日)
- @param timeStamp 时间
- @return bool
- */
- static func getCurrentTimeWithYMD() -> String{
- let date = NSDate()
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd"
- return formatter.string(from: date as Date)
- }
- }
|