java中给定特定时区的日期如何转换成其他的日期,参考以下代码:
package com.findsrc;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;
public class TestTimeZone {
@Test
public void test() throws Throwable {
//创建一个GMT+0的时区的日期
Date d1 = DateUtils.parseDate("2020-10-22T07:28:40+00:00", "yyyy-MM-dd'T'HH:mm:ssXXX");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
//指定目标时区GMT+8
df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//打印转换的结果
System.out.println(df.format(d1));
//打印内容
//2020-10-22T15:28:40+08:00
}
}
全部评论