Skip to content

Instantly share code, notes, and snippets.

@GuilhE
Last active May 9, 2024 12:17
Show Gist options
  • Save GuilhE/45e67f1f41e83ef0d9c4e3d77d7bcec1 to your computer and use it in GitHub Desktop.
Save GuilhE/45e67f1f41e83ef0d9c4e3d77d7bcec1 to your computer and use it in GitHub Desktop.
Medium articles - What's Native
import Foundation
import SharedModule
func formatDateTimeWithLocale(date: Kotlinx_datetimeLocalDate, pattern: String) -> String {
let formatter = DateFormatter()
formatter.dateFormat = pattern
formatter.locale = Locale.current
return formatter.string(from: date.toDate())
}
extension Kotlinx_datetimeLocalDate {
func toDate() -> Date {
var components = DateComponents()
components.year = Int(self.year)
components.month = Int(self.monthNumber)
components.day = Int(self.dayOfMonth)
return Calendar.current.date(from: components)!
}
}
//will print for example 09 Março, 09 March, 3月9日...
let sharedObject = SharedObjectsProvider().sharedObject()
print(formatDateTimeWithLocale(date: sharedObject.currentDate, pattern: "dd MMMM"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment