Java - Format date and time in the default locale


It uses a ZonedDateTime argument that holds the current date/time with time zone.

Uppercase variant 'T' formats the argument in uppercase letters.


import java.time.ZonedDateTime;

public class Main {
  public static void main(String[] args) {
    ZonedDateTime currentTime =;

    System.out.printf("%tA %<tB %<te, %<tY %n", currentTime);
    System.out.printf("%TA %<TB %<te, %<tY %n", currentTime);
    System.out.printf("%tD %n", currentTime);
    System.out.printf("%tF %n", currentTime);
    System.out.printf("%tc %n", currentTime);
    System.out.printf("%Tc %n", currentTime);

  }//from w w  w. j a  v  a  2s  .  c o  m


Related Topic