Java Data Type How to - Format date as for of Jun 22 2010 09:59 AM PDT








Question

We would like to know how to format date as for of Jun 22 2010 09:59 AM PDT.

Answer

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
  public static void main(String[] argv) {
    DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");
    ZonedDateTime arrivalDate = ZonedDateTime.now();
    String landing = arrivalDate.format(format);
    System.out.printf("Arriving at :  %s %n", landing);
  }//from www .ja  v  a  2s .  c o  m
}

The code above generates the following result.