Java - Format date and time in the default locale

Introduction

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

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

Demo

import java.time.ZonedDateTime;

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

    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  2  s.c  o  m*/
}

Result

Related Topic