Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift获取自定义日期(时间)_Swift_Date_Time_Calendar - Fatal编程技术网

Swift获取自定义日期(时间)

Swift获取自定义日期(时间),swift,date,time,calendar,Swift,Date,Time,Calendar,我无法从Date()获取具体时间。我在collectionView上有时间标签。我怎样才能得到正确的时间 此代码允许我获取完整数据 private func recordUser() { let confirmationPayViewController = kMainStoryboard.instantiateViewController(withIdentifier: "EVConfirmationPayViewController") as! EVConfirmationPayV

我无法从Date()获取具体时间。我在collectionView上有时间标签。我怎样才能得到正确的时间

此代码允许我获取完整数据

private func recordUser() {

    let confirmationPayViewController = kMainStoryboard.instantiateViewController(withIdentifier: "EVConfirmationPayViewController") as! EVConfirmationPayViewController
    confirmationPayViewController.modelController = MedicalRecordModelController()


    guard let selectedIndexes = collectionView?.indexPathsForSelectedItems else { return }
    print("selectedIndexes: \(selectedIndexes)")
    for i in 0..<selectedIndexes.count {
        let indexPath = selectedIndexes[i]

        if indexPath.section == 1 {

            let date = todaysTimes[indexPath.item].start
            print("date: \(date)")  // date: 2018-07-31 14:00:00 +0000

            let df = DateFormatter()
            df.dateFormat = "dd MMMM, HH:mm"
            df.timeZone = TimeZone.current
            df.locale = Locale(identifier: "ru_RU")

            confirmationPayViewController.modelController.medicalRecord.date = df.string(from: date)
            print("df2: \(df.string(from: date))")  //df2: 31 july, 05:00
        }
    }

    present(confirmationPayViewController, animated: true, completion: nil)
}
private func recordUser(){
将confirmationPayViewController=kmInstoryBoard.InstanceEviewController(标识符为:“EVConfirmationPayViewController”)设置为!EVConfirmationPayViewController
确认PayViewController.modelController=MedicalRecordModelController()
guard let SelectedIndex=collectionView?.InExpathsForSelectedItems else{return}
打印(“SelectedIndex:\(SelectedIndex)”)

对于0中的i,请澄清您试图实现的目标是什么?您正在以不同的日期格式显示的日期,因此时间发生了变化。如果您希望在存储API或任何其他来源的日期时使用相同的日期格式…@StepanValchyshyn我希望在confirmationPayViewController.modelController.medicalRe上获得相同的数据日期