Java Data Type How to - Format date time in form of 'June 22, 2015 (In Time Zone: America/Los_Angeles)'








Question

We would like to know how to format date time in form of 'June 22, 2015 (In Time Zone: America/Los_Angeles)'.

Answer

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
//from  ww w.  ja v a 2  s .com
public class Main {

  public static void main(String[] args) {
    DateTimeFormatter obscurePattern = DateTimeFormatter.ofPattern("MMMM dd, yyyy '(In Time Zone: 'VV')'");
    ZonedDateTime zonedNow = ZonedDateTime.now();
    System.out.println(obscurePattern.format(zonedNow));
  }
}

The code above generates the following result.