Java DateTimeFormatter format LocalDateTime to String like '09 o'clock AM'
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Main { public static void main(String[] args) { DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("hh 'o''clock' a"); LocalDateTime now = LocalDateTime.now(); String output = now.format(dateFormatter); System.out.println(output);//from w w w. ja v a 2s . c o m } }