最近与头条对接,RSS内容中需要用到GMT时间,发现网络上大多还是通过SimpleDateFormat来实现的,jdk1.8以后DateTimeFormatter使用广泛,因此做了个jdk1.8实现GMT的例子供需要的同学参考。
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("EEE,d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
dateTimeFormatter.withZone(TimeZone.getTimeZone("GMT").toZoneId());
String localDateTime = LocalDateTime.now().format(dateTimeFormatter);