
Enhances date, time, and string formatting with flexible styles and localization, aiming to improve existing string formatting functions. Offers basic, medium, and long format options.
This library for set up for Kotlin Multiplatform (KMP)
Feel free to fork it and make improvements, I'll keep up as best I can.
Note: this library currently uses nl.jacobras:Human-Readable for relative time, however it is not all tha compatible and as time goes on, we expect to replace it.
implementation("io.github.aughtone:format-datetime:${version}")This function is meant as a replacement for the string format function in java.
The intention is to improve string formatting so that its more robust, and it will probably move to a different library, so you should consider it unstable.
"Hello %1, today is %2".format("World", "Monday") // Returns "Hello World, today is Monday"
"Value: %1, Value2: %2".format(10, "test") // Returns "Value: 10, Value2: test"Date and time formatting are what this library is all about and there are several ways to do it.
// 1. Basic Usage with Defaults (Short Date and Time) in the local time zone.
val now = Clock.System.now().toLocalDateTime()
val formattedNow = now.format(DateTimeStyle.SHORT, DateTimeStyle.SHORT)
println("Now (Short Date & Time): $formattedNow")
// example output : Now (Short Date & Time): 10/26/24, 8:56 PM
// 2. Medium Date and Time
val mediumFormatted = now.format(DateTimeStyle.MEDIUM, DateTimeStyle.MEDIUM)
println("Now (Medium Date & Time): $mediumFormatted")
// example output : Now (Medium Date & Time): Oct 26, 2024, 8:56:56 PM
// 3. Long Date and Time
val longFormatted = now.format(DateTimeStyle.LONG, DateTimeStyle.LONG)
println("Now (Long Date & Time): $longFormatted")
// example output : Now (Long Date & Time): October 26, 2024 at 8:56:56 PM GMT+1https://en.wikipedia.org/wiki/Date_and_time_representation_by_country https://en.wikipedia.org/wiki/Thai_six-hour_clock https://en.wikipedia.org/wiki/Italian_six-hour_clock https://en.wikipedia.org/wiki/Common_Locale_Data_Repository
Bugs can go into the issue tracker, but you are probably going to get faster support by creating a PR.
This library for set up for Kotlin Multiplatform (KMP)
Feel free to fork it and make improvements, I'll keep up as best I can.
Note: this library currently uses nl.jacobras:Human-Readable for relative time, however it is not all tha compatible and as time goes on, we expect to replace it.
implementation("io.github.aughtone:format-datetime:${version}")This function is meant as a replacement for the string format function in java.
The intention is to improve string formatting so that its more robust, and it will probably move to a different library, so you should consider it unstable.
"Hello %1, today is %2".format("World", "Monday") // Returns "Hello World, today is Monday"
"Value: %1, Value2: %2".format(10, "test") // Returns "Value: 10, Value2: test"Date and time formatting are what this library is all about and there are several ways to do it.
// 1. Basic Usage with Defaults (Short Date and Time) in the local time zone.
val now = Clock.System.now().toLocalDateTime()
val formattedNow = now.format(DateTimeStyle.SHORT, DateTimeStyle.SHORT)
println("Now (Short Date & Time): $formattedNow")
// example output : Now (Short Date & Time): 10/26/24, 8:56 PM
// 2. Medium Date and Time
val mediumFormatted = now.format(DateTimeStyle.MEDIUM, DateTimeStyle.MEDIUM)
println("Now (Medium Date & Time): $mediumFormatted")
// example output : Now (Medium Date & Time): Oct 26, 2024, 8:56:56 PM
// 3. Long Date and Time
val longFormatted = now.format(DateTimeStyle.LONG, DateTimeStyle.LONG)
println("Now (Long Date & Time): $longFormatted")
// example output : Now (Long Date & Time): October 26, 2024 at 8:56:56 PM GMT+1https://en.wikipedia.org/wiki/Date_and_time_representation_by_country https://en.wikipedia.org/wiki/Thai_six-hour_clock https://en.wikipedia.org/wiki/Italian_six-hour_clock https://en.wikipedia.org/wiki/Common_Locale_Data_Repository
Bugs can go into the issue tracker, but you are probably going to get faster support by creating a PR.