宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
//  DateExtension.swift
//  YYBase
//
//  Created by alvin_y on 2020/3/26.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
import SwiftDate
extension Date{
    
    /// 当前时间戳
    func timeStamp() -> Int {
        return Int(self.localDate().timeIntervalSince1970)
    }
    /// 本地Date
    func localDate() -> Date {
        let date = Date()
        let zone = TimeZone.current
        let interval = zone.secondsFromGMT(for: date)
        return date.addingTimeInterval(TimeInterval(interval))
    }
    
    /// 格式化时间
    /// - Parameter format: 时间格式
    func dateFormat(format: String) ->  String{
        let d = DateFormatter()
        d.dateFormat = format
        return d.string(from: self)
    }
}
 
extension Date
{
    func zoneFormat(_ format: String) -> String {
        let rome = Region(calendar: Calendars.gregorian, zone: Zones.current,
                          locale: Locales.current)
        let date = DateInRegion(Date(), region: rome)
        return date.toFormat(format)
    }
}