从API我得到的时间字符串“13:00:00Z”在这种格式,它是GMT 0时区。我想把它调整到我的时区,即GMT +4。
qv7cva1a1#
首先你把时间转换成UTC,然后把UTC时间转换成你的当地时区。例如:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); try { Date utcDate = simpleDateFormat.parse("Your date"); SimpleDateFormat yourDateFormat = new SimpleDateFormat("dd MMM yyyy · HH'h'mm", Locale.getDefault()); String dateString = simpleDateFormat.format(utcDate); binding.orderdate.setText(dateString); } catch (Exception e) { e.printStackTrace(); }
1条答案
按热度按时间qv7cva1a1#
首先你把时间转换成UTC,然后把UTC时间转换成你的当地时区。例如: