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

Time:11-18

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

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

CodePudding user response:

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.

  • Related