let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd, a h:mm"
let date = dateFormatter.date(from: authHistory.regDtString)
dateFormatter.dateFormat = "yyyy-MM-dd"
let stringDate = dateFormatter.string(from: date ?? Date())
DateFormatter를 사용하기 위해서 멀쩡한 String형을 Date형으로 만들었다가 다시 내가 원하는 양식의 String형으로 바꿔치기 하는 코드... 크게 설명할 부분도 없고, 직관적으로 이해할 수 있는 내용인 것 같습니다.. dateFormatter.date는 String -> Date로, 반대로 dateFormatter.string은 Date -> String이라는 점만 기억하면 될 것 같아요!
'iOS Swift > Today I Learned' 카테고리의 다른 글
tableView의 header, footer view 색 변경하기 (0) | 2023.01.05 |
---|---|
filter 및 tableView section 활용하기 (0) | 2022.12.30 |
CIImage, CGImage, UIImage 변환 및 개념 정리 (0) | 2022.12.28 |
이미지를 circle로 만들어주는 clipToBounds (0) | 2022.12.22 |
UIImage nil 확인하기(optional, non-optional) (1) | 2022.12.21 |