Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert string in format "yyyy-mm-dd hh:mm:ss" to localDateTime? #128

Closed
ccc-sseylani opened this issue Jun 7, 2021 · 5 comments
Closed
Labels
formatters Related to parsing and formatting

Comments

@ccc-sseylani
Copy link

I am getting a date in a format like this "2021-03-26 22:02:53" from the API which is not ISO format, and I created a custom serializer for it but I am getting an error.
I also do not want to use ISO format, and I want to send back the date as "yyyy-mm-dd hh:mm:ss".

Since We can not use Java.Date in Kotlin multiplatform, what is the proper solution to serialize date format like this?

image

image

Thanks

@dkhalanskyjb dkhalanskyjb added the formatters Related to parsing and formatting label Jun 16, 2021
@dkhalanskyjb
Copy link
Collaborator

Sorry, we don't have such functionality currently. There are many requests for it though ( formatters Related to parsing and formatting ), so we are thinking about this.

@ilya-g
Copy link
Member

ilya-g commented Dec 16, 2021

The format looks very similar to the ISO format of LocalDateTime, except that the date and time components are separated with a space instead of T. So as a workaround, you can replace ' ' with 'T' and use LocalDateTime.parse to parse the result:

LocalDateTime.parse("2021-03-26 22:02:53".replaceFirst(' ', 'T')

@galipkaya
Copy link

Can this issue be solved by giving an optional format string parameter to LocalDateTime.parse and using this format parameter in type DateTimeFormatter. ofPattern?

@DenisGithuku
Copy link

You can actually use the date time formatter to parse the string then use the local date to parse into your requirements
            val formatter =DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")             val formattedDate = LocalDate.parse(date, formatter)

@dkhalanskyjb
Copy link
Collaborator

dkhalanskyjb commented Nov 7, 2022

Except that's Java. This library doesn't have DateTimeFormatter.

dkhalanskyjb added a commit that referenced this issue Feb 20, 2024
Fixes #39
Fixes #58
Fixes #90
Fixes #128
Fixes #133
Fixes #139
Fixes #211
Fixes #240
Fixes #83
Fixes #276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatters Related to parsing and formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@ilya-g @DenisGithuku @dkhalanskyjb @galipkaya @ccc-sseylani and others