Java Date parse String like "22:14:02 -0500" with time zone offset

Description

Java Date parse String like "22:14:02 -0500" with time zone offset

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

  static public void main(String[] args) {
    DateFormat formatter = null;//from ww w  .  j av a  2 s . c  om
    Date date = null;
    try {
      formatter = new SimpleDateFormat("HH:mm:ss Z");
      date = (Date) formatter.parse("22:14:02 -0500");
      System.out.println(date);
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
}



PreviousNext

Related