0

How do I get the current time in the below format. Timezone is Europe/London:-

04:47 PM GMT+1

I have tried various different ways, including below code:-

ZoneId zone = ZoneId.of("Europe/London");
Locale locale = Locale.forLanguageTag("en-GB");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
        "dd MMM uuuu HH:mm OOOO", locale);

ZonedDateTime dateTime = Instant.now().atZone(zone);
String result = dateTime.format(formatter);

This gets me -->30 Mar 2021 18:36 GMT+01:00. But its not what I want.

1
  • Nice solution that you’ve found there. Do we think it will be helpful to other readers? I could imagine that it might. If you think, please post it as an answer to your own question, and I shall be happy to upvote. If you rather think not, please delete the question. You have got a delete link under it.
    – Anonymous
    Mar 30, 2021 at 19:06

1 Answer 1

0

Update:- Its resolved now. This pattern helped----->> DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "hh:mm a O", locale);

1
  • If you want upvotes, you need to actually write the answer properly. Format it properly, and explain what the code does and how it does it. Links to the relevant documentation would help too.
    – Stephen C
    Aug 10, 2022 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.