//
//  Date+.swift
//  Toolboxes
//
//  Created by 研发2组 on 2024/9/27.
//

import Foundation

extension Date {
   func getCurrentDayStart(_ isDayOf24Hours: Bool)-> Date {
       let calendar:Calendar = Calendar.current;
       let year = calendar.component(.year, from: self);
       let month = calendar.component(.month, from: self);
       let day = calendar.component(.day, from: self);
   
       let components = DateComponents(year: year, month: month, day: day, hour: 0, minute: 0, second: 0)
       return Calendar.current.date(from: components)!
   }
    
    // 格式化为 HH:mm:ss 格式
       func formattedTime() -> String {
           let dateFormatter = DateFormatter()
           dateFormatter.dateFormat = "HH:mm:ss"
           return dateFormatter.string(from: self)
       }
    
    
    // 获取今天的日期字符串
    func todayDateString() -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "MM.dd"
        return dateFormatter.string(from: Date())
    }
}
