Java 如何将UTC转换为SGT

Java 如何将UTC转换为SGT,java,utc,Java,Utc,下面是我用来将UTC转换为SGT的两种方法,但都不太成功。请帮助我将UTC转换为SGT List<String> list0 = new ArrayList<>(); List<String> list1 = new ArrayList<>(); public void FirstTradingTime() throws ParseException { list0 .add("2018-05-10T05:56:35.557Z");

下面是我用来将UTC转换为SGT的两种方法,但都不太成功。请帮助我将UTC转换为SGT

List<String> list0 = new ArrayList<>();
List<String> list1 = new ArrayList<>();

public void FirstTradingTime() throws ParseException {
     list0 .add("2018-05-10T05:56:35.557Z");
       for(int i=0; i<list0 .size();i++) {
       String FirstTime = list0 .get(i);
       DateFormat pstFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
       pstFormat.setTimeZone(TimeZone.getTimeZone("PST"));
       Date date = pstFormat.parse(String.valueOf(FirstTime));          
       DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
       utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
       list1 .add(utcFormat.format(date));
  }
  System.out.println("FirstTradingTime "+list1 ;
}
List list0=new ArrayList();
List list1=新的ArrayList();
public void FirstTradingTime()引发异常{
列表0.添加(“2018-05-10T05:56:35.557Z”);

对于(int i=0;i而言,错误出现在
时区。getTimeZone(“SGT”)
,因为id
SGT
不存在。该时区的id是
Asia/Singapore
,您可以通过
TimeZone.getTimeZone(“Asia/Singapore”)
获得它

试试这个:

DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date utcDate = utcFormat.parse("2018-05-10T05:56:35.557");

DateFormat sgtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
sgtFormat.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
String sgtString = sgtFormat.format(utcDate);

第二次输出的可能重复似乎与预期输出的时间相同,对吗?
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date utcDate = utcFormat.parse("2018-05-10T05:56:35.557");

DateFormat sgtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
sgtFormat.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
String sgtString = sgtFormat.format(utcDate);