Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to create a Instant class variable in kotlin with my own timestamp

Till now i was using

val date = Instant.now(Clock.system(ZoneId.of("UTC")))

to generate the instant timestamp.
Now I need to substitute it with the date that I want to specify for example "2021-05-03T00:00:00.000Z". When i insert it as a string into the function, the idea gives me the error "Type mismatch. Required: Instant! Found: String". I can’t change the function as I have no such access to it. So i need to somehow turn this date into "Instant!" class.

this is how the function that i can’t change looks like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    public TimeTZ(Instant timestamp, Boolean isLocal) {
        this.timestamp = timestamp;
        this.isLocal = isLocal;
    }

>Solution :

val date = Instant.parse("2021-05-03T00:00:00.000Z")

Converting a string to an Instant (or other typed value) is called parsing. So use the parse method of Instant.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading