ios swift 时间处理总结

68 阅读1分钟

时间处理方式 慢慢积累

//
//  DateUtil.swift
//  BookKeeping
//
//  Created by gy on 2022/12/6.
//

import Foundation
// 可以获取到年 月 日 时 分 秒 自己组合使用
func getTimes() ->[Int]{
    let calendar = Calendar(identifier: .gregorian)
    let coms = calendar.dateComponents([.year,.month,.day,.hour,.minute,.second], from: Date())
    let times = [coms.year!,coms.month!,coms.day!,coms.hour!,coms.minute!,coms.second!]
    return times
}

func getYear() -> Int{
    return getTimes()[0]
}

func getMonth()->Int{
    return getTimes()[1]
}