i have string date like this
2020-05-19 10:46:09 this is Asia/Jakarta time
i want to convert become GMT and here my code
String created = New_tradingHistory_trade.getCreated_at();
Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(created);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String CreatedGMT = sdf.format(date1);
System.out.print(CreatedGMT);
what i got always like 2020-05-19 10:46:09 2020-05-19 10:46:09 my question is how to convert my date to GMT ?
you should use the java-8 date time api and stop using legacy Date and SimpleDateFormat
Asia/Jakarta
GTM
date time which is equal to UTC
String input = "2020-05-19 10:46:09";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTime = LocalDateTime.parse(input,formatter);
ZonedDateTime zoneDateTime = localDateTime.atZone(ZoneId.of("Asia/Jakarta"));
System.out.println(zoneDateTime);
ZonedDateTime gmtDateTime = zoneDateTime.withZoneSameInstant(ZoneOffset.UTC);
System.out.println(gmtDateTime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With