//
//  DateTime.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/3/27.
//

import Foundation
@_exported import SwiftDate
//MARK: - Date扩展
extension Date {
    ///获取当前时区时间点
    func timeZone() -> Date{
        //设置源日期时区
        let sourceTimeZone = NSTimeZone(abbreviation: "UTC")
        //或GMT
        //设置转换后的目标日期时区
        let destinationTimeZone = NSTimeZone.local as NSTimeZone
        //得到源日期与世界标准时间的偏移量
        let sourceGMTOffset = sourceTimeZone?.secondsFromGMT(for: self)

        //目标日期与本地时区的偏移量
        let destinationGMTOffset = destinationTimeZone.secondsFromGMT(for: self)

        //得到时间偏移量的差值
        let interval = TimeInterval((destinationGMTOffset ) - (sourceGMTOffset ?? 0))
        //转为现在时间
        let destinationDateNow = Date(timeInterval: interval, since: self)
        return destinationDateNow
    }
}
