// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateParseFormat {
    private static DateFormat dfoffset;
    private static DateFormat dfminus4;
    private static DateFormat dfplus2;
    private static void test(String s) throws ParseException {
        System.out.println("Time string: " + s);
        Date d = dfoffset.parse(s);
        System.out.println("Binary time when parsed: " + d.getTime());
        System.out.println("Formatted in -4: " + dfminus4.format(d));
        System.out.println("Formatted in +2: " + dfplus2.format(d));
    }
    public static void main(String[] args) throws ParseException {
        dfoffset = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssz");
        dfminus4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dfminus4.setTimeZone(TimeZone.getTimeZone("GMT-04:00"));
        dfplus2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dfplus2.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
        test("2009-06-26 14:13:00-0400");
        test("2009-06-26 14:13:00+0200");
    }
}
