datePicker.addTarget(self, action: #selector(datePickerChanged(datePicker:)), for: UIControlEvents.valueChanged)
dateFormat()
} //this works
func dateFormat() {
let today = NSDate()
let dateFormatter = DateFormatter()
let short = DateFormatter.Style.short
dateFormatter.dateStyle = short
dateFormatter.dateFormat = "MM-dd-YYYY"
let startDate = dateFormatter.string(from: datePicker.date)
dateLbl.text = startDate
//this works but datePicker date when moved will not update
let thirtyDays = NSCalendar.current.date(byAdding: Calendar.Component.day,value: 30, to: today as Date)
let tomorrowSixty = dateFormatter.string(from: thirtyDays!)
sixtyDay.text = tomorrowSixty
}
func datePickerChanged(datePicker:UIDatePicker){
dateFormat()
}
}
답변
업데이트되지 않습니다.
이제 sixtyDay
레이블을 datePicker 날짜의 30 일 이후의 날짜로 설정하려면 datePicker.date
을 오늘 날짜 대신 date(byAdding:)
으로 사용해야합니다.
func dateFormat() {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
let startDate = dateFormatter.string(from: datePicker.date)
dateLbl.text = startDate
//this works but datePicker date when moved will not update
let thirtyDays = Calendar.current.date(byAdding: .day, value: 30, to: datePicker.date)
let tomorrowSixty = dateFormatter.string(from: thirtyDays!)
sixtyDay.text = tomorrowSixty
}
func datePickerChanged(datePicker:UIDatePicker){
dateFormat()
}
참고 : 당신이 다음 필요 DateFormatter
로 dateStyle
을 설정하지 않으려면 DateFormatter
와 dateFormat
을 설정하는 경우에는 올바른 년 포맷터 yyyy
하지 YYYY
입니다.
그것이 효과가 있습니까? –
datepicker 다이얼을 이동하면 빌드의 sixtyDay.text가 업데이트되지 않습니다 ... dateLbl.text에서는 날짜가 변경되지만 sixtyday.text에서는 변경되지 않으며 동일한 현재 날짜로 유지됩니다 – rpbones531
@ rpbones531 편집 된 응답 변경 확인 'let thirtyDays = Calendar.current.date (byAdday : value, 30, to : datePicker.date) '행 –
- 1. 스위프트 <<, ><, <=< and > = <
- 2. 뷰에서 <% 및 <% =를 모두 사용하는 이유는 무엇입니까?
- 3. PHP <<< OUT 및 OUT;
- 4. <? 및 <? php
- 5. SBT, << = 및 : =
- 6. Swift에서 +++ 및 <<<는 무엇입니까?
- 7. R의 대입 연산자 : '<-'및 '<< -'
- 8. <텍스트 입력에 <를 추가하는 방법. <Back
- 9. Tortoise svn <<<<를 파일에 추가 중!
- 10. 루비 "+ ="및 "<<"문자열
- 11. FLOAT (10,6)을 사용하는 MySQL - BETWEEN 연산자는> = 및 <= 대신 <> 및 <= 대신에 작동합니다.
- 12. PHP에서 <? php 대신 <?
- 13. <대신 ASP.NET에서 렌더링 <
- 14. `대신 <<`의 Reduce` -`
- 15. 스위프트 3에서 UnsafeMutablePointer <UInt>을 사용하는 방법?
- 16. <m <
- 17. Heredoc <<< 또는 <<?
- 18. & gt; & lt; 및 대신 & of <XmlWriter.writeElementString>의 경우
- 19. Visual Studio에서 mine :: iterator <> 대신 <: iterator <>를 사용하는 이유는 무엇입니까?
- 20. '='을 (를) 파이썬에서 비트 연산자에 추가하면 무엇이 있습니까? (예 : '<<'대신 '<<')
- 21. 내가 내 프로젝트 호스팅으로 <em>ToirtoiseSVN</em> 및 <em>AnkhSVN</em> 및 <strong>GoogleCode</strong> 및 <strong>sourceforge.net</strong>를 사용 전주
- 22. <-chan 및 chan <- 단방향 통신을 사용하는 방법?
- 23. 로깅 성능 및 운영자 <<
- 24. << 연산자 및 상속 된 클래스
- 25. 어떻게 PHP simplexml을 <대신 저장할 수 있습니까? 대신 <
- 26. github add <<<<<<< HEAD
- 27. spaCy 및 텍스트 청소 '<br /><br />'
- 28. <? php 대신 <? =를 사용하도록 PHP를 설정했습니다.
- 29. 어떻게 <code>Xcode 7.3.1</code><code>Swift 2.2</code>에 내가 <code>SwiftyJSON</code>를 설치하는 <code>cocoapods</code>를 사용하고 2.2
- 30. boost :: optional에 대한 비교 (<), 출력 (<<) 및 할당 (=)
dateLbl의 출처는 어디입니까? – onnoweb
dateLbl은 콘센트입니다. IBOutlet weak var datePicker : UIDatePicker! IBOutlet weak var dateLbl : UILabel! IBOutlet weak var sixtyDay : UILabel! – rpbones531