android timestamp parsing gone wrong(always in 1970)

后端 未结 4 1935
夕颜
夕颜 2020-12-16 07:08

im trying to convert a string(with unix timestamp) to an date with the format ( dd-MM-yyyy)

and this is working partly. The problem im having now is that my date is

4条回答
  •  别那么骄傲
    2020-12-16 07:30

    You are using the wrong format string in the first line:

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
    

    mm is minutes. Use MM (months) instead.

    edit A Unix timestamp is a number of seconds since 01-01-1970 00:00:00 GMT. Java measures time in milliseconds since 01-01-1970 00:00:00 GMT. You need to multiply the Unix timestamp by 1000:

    cal.setTimeInMillis(dateMulti * 1000L);
    

提交回复
热议问题