I have 3 messages, it message was sent in sequence, server give me 4 ISO8601 time:
2017-01-11T12:34:21.948631
2017-01-11T12:34:22.425915
2017-01-11T12:34:22.954749
2017-01-11T12:34:23.473965
My logic convert to current date
public class ISO8601{
static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSSSS");
String isodate;
long timestamp = 0;
public ISO8601(String isodate){
dateformat.setTimeZone(TimeZone.getTimeZone("UTC"));
this.isodate = isodate;
try {
Date date = dateformat.parse(this.isodate);
timestamp = date.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
}
public long getTime(){
return timestamp;
}
}
class for convert to date
public class HelperMethods {
public static CharSequence getFormatTime(long time) {
DateFormat sdf = new SimpleDateFormat("hh:mm:ss yyyy-MM-dd");
Date netDat = new Date(time);
return sdf.format(netDat);
}
}
Now i try use this class and method for conver ISO8601 to normal time
Log.e("1", String.valueOf(HelperMethods.getFormatTime(new ISO8601("2017-01-11T12:34:21.948631").getTime())));
Log.e("2", String.valueOf(HelperMethods.getFormatTime(new ISO8601("2017-01-11T12:34:22.425915").getTime())));
Log.e("3", String.valueOf(HelperMethods.getFormatTime(new ISO8601("2017-01-11T12:34:22.954749").getTime())));
Log.e("4", String.valueOf(HelperMethods.getFormatTime(new ISO8601("2017-01-11T12:34:23.473965").getTime())));
And it output:
01:50:09 2017-01-11
01:41:27 2017-01-11
01:50:16 2017-01-11
01:42:16 2017-01-11
If i will do * 1000L timestamp like this:
public static CharSequence getFormatTime(long time) {
DateFormat sdf = new SimpleDateFormat("hh:mm:ss yyyy-MM-dd");
Date netDat = new Date(time * 1000L);
return sdf.format(time);
}
It output:
09:00:31 48999-02-14
08:05:15 48999-02-08
10:59:09 48999-02-14
09:42:45 48999-02-09
I cant understand why i cant curectly convert date