라이브 상세 - 날짜 포맷 yyyy년 MM월 dd일 (E) a hh시 mm분 로 수정

This commit is contained in:
Yu Sung 2023-11-14 12:50:16 +09:00
parent 41b7247a44
commit e98847179a
2 changed files with 6 additions and 2 deletions

View File

@ -14,11 +14,15 @@ extension Optional where Wrapped == String {
} }
extension String { extension String {
func convertDateFormat(from: String, to: String) -> String { func convertDateFormat(from: String, to: String, locale: Locale? = nil) -> String {
let fromFormatter = DateFormatter() let fromFormatter = DateFormatter()
fromFormatter.dateFormat = from fromFormatter.dateFormat = from
fromFormatter.timeZone = TimeZone(identifier: TimeZone.current.identifier) fromFormatter.timeZone = TimeZone(identifier: TimeZone.current.identifier)
if let locale = locale {
fromFormatter.locale = locale
}
if let date = fromFormatter.date(from: self) { if let date = fromFormatter.date(from: self) {
return date.convertDateFormat(dateFormat: to) return date.convertDateFormat(dateFormat: to)
} else { } else {

View File

@ -94,7 +94,7 @@ struct LiveDetailView: View {
.padding(.top, 6.7) .padding(.top, 6.7)
HStack(spacing: 0) { HStack(spacing: 0) {
Text(room.beginDateTime) Text(room.beginDateTime.convertDateFormat(from: "yyyy.MM.dd EEE hh:mm a", to: "yyyy년 MM월 dd일 (E) a hh시 mm분", locale: Locale(identifier: "en_US_POSIX")))
.font(.custom(Font.medium.rawValue, size: 12)) .font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "bbbbbb")) .foregroundColor(Color(hex: "bbbbbb"))