Datetime.Parse returning wrong time

Asked

Viewed 132 times

-1

Hi, I’m doing this:

DateTime horaInicio = DateTime.parse(parsedJson['comeco']);

Value of parsedJson:

inserir a descrição da imagem aqui

As you can see in parsedJson it’s 7:38:33 and this is the time I wanted, but I have as an answer:

inserir a descrição da imagem aqui

1 answer

0

The function is not wrong, the problem is that you are not taking into account the time zone (Time-zone).

This is returned in your JSON:

2020-08-04T07:38:33-04:00

Is being converted to:

2020-08-04 11:45:38.000Z

The "wrong" time is because of the time zone "04:00".

Parts of the date

JSON: 2020-08-04T07:38:33-04:00

Date: 2020-08-04 (yyyy-MM-dd)

Time: 11:45:38.000 (hh:mm:ss:zzz)

Spindle: 04:00

Adjustment

You can try using the toLocal() in the moment of conversion

DateTime.parse(parsedJson['comeco']).toLocal()
  • Cool, I get it now, but how do I do it so he gets the right time zone?

  • @Jeffhenrique Try to do Datetime.parse(parsedJson['start']). toLocal()

  • Time zone would justify the difference in hours, but why does it have a difference in minutes too?

  • @user140828 There is a whole calculation to be generated a date and time, hence you have to enter the classes to understand, this difference in minutes/ seconds if gives so.

  • 1

    @Matheus, can you give me a reference? I don’t think that your statement is correct.

  • @user140828 What I said doesn’t really make sense, but in my tests here the minute/second were not changed as quoted in the question, only the time has changed.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.