Convert from Millisecond to String of Date

后端 未结 2 1836
我寻月下人不归
我寻月下人不归 2021-01-29 05:55

I try to convert from Milliseconds to string of date. However, the result is not correct as my expected.

The input is milliseconds (Ex: 1508206600485)

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 06:11

    Basing on @phlaxyr, I have solved my problem. You can get your time zone in this link below

    http://tutorials.jenkov.com/java-date-time/java-util-timezone.html

    public static String getDate(long milliSeconds) {
        SimpleDateFormat formatter = new SimpleDateFormat("hh:mm dd/MM/yyyy");
        formatter.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
        String dateString = formatter.format(new Date(milliSeconds));
        return dateString;
    }
    

提交回复
热议问题