Locale-specific morning/afternoon indicator in Java



Locale-specific morning/afternoon indicator is the AM/PM marker indicator.

Use the ‘p’ conversion character to display AM/PM.

System.out.printf("Morning/afternoon indicator: %tp",d);

Example

 Live Demo

import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      Date d = new Date();
      System.out.printf("Morning/afternoon indicator: %tp",d);
      System.out.printf("\nMorning/afternoon indicator: %Tp",d);
   }
}

Output

Morning/afternoon indicator: pm
Morning/afternoon indicator: PM
Updated on: 2020-06-27T05:36:27+05:30

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements