Time difference

17 views
Skip to first unread message

Rubén V

unread,
Dec 11, 2020, 1:49:52 AM12/11/20
to CodenameOne Discussions
Hi,

I have a small method that returns a string with the time of a date. This works fine when I show the start and end time, but the difference appears wrong. Example: Start Time = 8:26:11, End Time = 8:26:13 and Difference = 7: 0: 1.

My method is:

    private String horaTexto(Long fecha) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        Date d = new Date(fecha);
        c.setTime(d);
        return c.get(java.util.Calendar.HOUR) + ":" + c.get(java.util.Calendar.MINUTE) + ":" + c.get(java.util.Calendar.SECOND);
    }

Thanks

Shai Almog

unread,
Dec 12, 2020, 2:04:03 AM12/12/20
to CodenameOne Discussions
Hi,
This is probably due to timezone differences which you're ignoring here. Check out the DateUtil class.
Reply all
Reply to author
Forward
0 new messages