Java Date ISO Parse parseISO8601DateString(String dateString)

Here you can find the source of parseISO8601DateString(String dateString)

Description

parse ISO Date String

License

Apache License

Declaration

public static Date parseISO8601DateString(String dateString)
            throws ParseException 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date parseISO8601DateString(String dateString)
            throws ParseException {
        // -> SimpleDateFormat uses GMT[-+]hh:mm for the TZ so first we need to
        //    convert the string with this value
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");

        //this is zero time so we need to add that TZ indicator for
        if (dateString.endsWith("Z")) {
            dateString = dateString.substring(0, dateString.length() - 1)
                    + "GMT-00:00";
        } else { // -> -0700 is valid but we need to change it to -07:00 for SimpleDateFormat
            dateString = dateString.replaceFirst("-(\\d\\d)(\\d\\d)",
                    "-$1:$2");

            int inset = 6;
            String s0 = dateString
                    .substring(0, dateString.length() - inset);
            String s1 = dateString.substring(dateString.length() - inset,
                    dateString.length());
            dateString = s0 + "GMT" + s1;
        }/*from  w  w w . j a  v a2  s .co m*/

        //System.out.println( "parseDate: [" + dateString + "]" );
        return df.parse(dateString);
    }
}

Related

  1. parseISO8601Date(String dateString)
  2. parseIso8601Date(String dateString)
  3. parseISO8601Date(String encoded, Date fallback)
  4. parseISO8601Date(String s)
  5. parseIso8601Date(String strDate)
  6. parseIso8601DateTimeOrDate(String datestr)
  7. parseISO8601String(String dateString)
  8. parseISO8601TimeAndDateString(String dateString)
  9. parseIso8601TimeStamp(String dateString)