You are on right approach but just use java-8 date time API module, first create DateTimeFormatter
with the input format representation
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z");
And then use OffsetDateTime
to parse string with offset
OffsetDateTime dateTime = OffsetDateTime.parse("Tue, 30 Apr 2019 16:00:00 +0800",formatter);
And the call the toLocalDateTime()
method to get the local time
LocalDateTime localDateTime = dateTime.toLocalDateTime(); //2019-04-30T16:00
If you want the output in particular format again you can use DateTimeFormatter
localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) //2019-04-30T16:00:00
Note : As @Ole V.V pointed in comment, after parsing the input string into util.Date you are getting the UTC
time
The class Date represents a specific instant in time, with millisecond precision.
So now if you convert the parsed date time into UTC
you get 2019-04-30T08:00Z
without offset, so you can use withOffsetSameInstant to convert it into any particular timezone
dateTime.withOffsetSameInstant(ZoneOffset.UTC)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…