Java Date Format ISO parseISODateFormat(String dateStr)

Here you can find the source of parseISODateFormat(String dateStr)

Description

parse ISO Date Format

License

Apache License

Declaration

public static String parseISODateFormat(String dateStr) 

Method Source Code

//package com.java2s;
/*/* w w w.  j a  va 2 s . c  o m*/
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import java.util.Locale;

public class Main {
    private static final SimpleDateFormat CREATION_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    private static final SimpleDateFormat LAST_MODIFIED_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    protected static final SimpleDateFormat GUNVOR_TOOLS_DATE_FORMAT = new SimpleDateFormat(
            "EEE, dd MMM yyyy HH:mm:ss z", Locale.getDefault());

    public static String parseISODateFormat(String dateStr) {

        if (dateStr == null)
            return null;

        String val = dateStr;

        try {
            if (dateStr.indexOf('T') == 10 && dateStr.endsWith("Z")) {
                Date date = CREATION_DATE_FORMAT.parse(dateStr);
                val = GUNVOR_TOOLS_DATE_FORMAT.format(date);

            } else if (dateStr.indexOf('T') == 10) {
                Date date = LAST_MODIFIED_DATE_FORMAT.parse(dateStr);
                val = GUNVOR_TOOLS_DATE_FORMAT.format(date);
            }

        } catch (ParseException e) {

        }

        return val;
    }
}

Related

  1. longToISODate(long longDate)
  2. makeDateISO8601(Date date)
  3. millisecondsToISO8601(long date)
  4. NowFormatISO()
  5. nowISO8601()
  6. parseIsoDateTime(final String isoDateString, final String dateFormat)
  7. timeToIso8601(long time, boolean includeTime)
  8. toBasicISO8601DateTime(Date value)
  9. toDateIso(Date date)