当前位置: 首页 > 工具软件 > SwiftDate > 使用案例 >

swift 获取年月日 swift 获取年月日时分秒(每一个单独获取) 和获取yy-mm-dd格式

鞠自明
2023-12-01
var calendar:Calendar = Calendar.current;

        var now = Date();

        var year = calendar.component(.year, from: now);

        var month = calendar.component(.month, from: now);

        var day = calendar.component(.day, from: now);

        var hour = calendar.component(.hour, from: now);

        var minute = calendar.component(.minute, from: now);
        var  formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd"
        formatter.timeZone = TimeZone.init(secondsFromGMT: 0)
        var dates = formatter.string(from: Date())

 

 类似资料: