DateTimeFormatter equivalent
See original GitHub issueIt is not included in the documentation so we would like to ask if Kotlinx Datetime has java.time.format.DateTimeFormatter
equivalent for formatting?
Here are the following usage we had with the Java DateTimeFormatter
val formattedDate: String
get() = LocalDate.parse(date, DateTimeFormatter.ISO_LOCAL_DATE_TIME).format(
DateTimeFormatter.ofPattern("MMM. dd, yyyy")
)
val formattedTime: String = Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault())
.toLocalDate().format(DateTimeFormatter.ofPattern("MM-dd-yyyy"))
LocalDateTime.parse(
lowDate,
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
)
Currently using coreLibraryDesugaringEnabled
for backward compatibility.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
DateTimeFormatter (Java Platform SE 8 ) - Oracle Help Center
Four letters outputs the full form of localized offset, equivalent to four letters of Offset-O. The output will be the corresponding localized offset...
Read more >Code equivalent from java 8 to java 7 of DateTimeFormatter ...
This question already has answers here: DateTimeFormatter formatter = DateTimeFormatter. ofPattern("yyyyMMdd"); String fecha = LocalDate. now() ...
Read more >Convert DateTimeFormatter withZoneUTC to java.time ...
Recipe Name: Convert DateTimeFormatter withZoneUTC to java.time equivalent ; Description: Convert DateTimeFormatter withZoneUTC to java.time equivalent ; Level:.
Read more >DateTimeFormatter - Android Developers
LocalDate date = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter. ... Four letters outputs the full form of localized offset, equivalent to ...
Read more >DateTimeFormatter.ShortTime Property - UWP - Microsoft Learn
A DateTimeFormatter object equivalent to one constructed with the "shorttime" template. Applies to. Product, Versions. WinRT, Build 10240, Build 10586, Build ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My usecase was very limited (and only needing to support Android & iOS) so I ended up just going for this very simple util, posting here incase it helps someone.
In
commonMain
:androidMain
:iosMain
:Yes.
Regarding the
LocalDateTime.parse
usage though, it closely resembles ISO-8601, so you can do that: