swift 상대적 시간, 1일전, 1시간 전,
1 일 전, 1 시간 전, 몇 분 전, 몇 분 후, 시간 후, 일 후, 리뷰를 쓴 시간을 유저에게 보여주게 되면서 저런 시간 표현이 필요했다. 아주 간단하게.. func relativeTime(in locale: Locale = .current, unitsStyle: RelativeDateTimeFormatter.UnitsStyle = .full) -> String { let formatter = RelativeDateTimeFormatter() formatter.unitsStyle = unitsStyle return formatter.localizedString(for: self, relativeTo: Date()) } public enum UnitsStyle : Int { case full = 0 /..
2020. 10. 20.
[swift Date, DateFormatter] Date->String , String->Date 일때 locale(identifier), TimeZone(abbreviation) 관계
앱을 개발하다 보면 흔지 Date 를 String(년,월,일,오전,오후,시간) 이런식으로 나타내야 할 때가 있다. 클라이언트와 서버와의 통신중 날짜 관련 포맷은 대부분 "2019-03-23T06:29:04.000Z" 이런 식의 포맷을 사용 할 것이다. 우리는 그럼 저 부분을 DateFormatter를 이용해서 date로 바꾸고 또는 년,월,일,오전,오후,시간 이런 식으로 나타낼 것이다. 그리고 UTC 기반이기 때문에 현재 Locale 과 TimeZone에 따라 그 나라에 맞게 아니면 절대적인 값을 표현할 것이다. Locale(로케일)은 세계 여러 나라들은 각자 다른 문화(언어, 날짜, 시간 등)을 갖고 있다. 프로그램의 국제화(Internationalization, 줄여서 i18n)는 사용자로 하여금 프..
2019. 11. 21.