Java Parse Date Pattern YYYY parseCoTDate(String dateString)

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

Description

parse Co T Date

License

Apache License

Declaration

public static Date parseCoTDate(String dateString) throws Exception 

Method Source Code

//package com.java2s;
/*//from  w ww  .  j ava2s  . co  m
 * #%L
 * CoTUtilities.java - Esri :: AGES :: Solutions :: Adapter :: CoT - Esri - 2013
 * org.codehaus.mojo-license-maven-plugin-1.5
 * $Id: update-file-header-config.apt.vm 17764 2012-12-12 10:22:04Z tchemit $
 * $HeadURL: https://svn.codehaus.org/mojo/tags/license-maven-plugin-1.5/src/site/apt/examples/update-file-header-config.apt.vm $
 * %%
 * Copyright (C) 2013 - 2014 Esri
 * %%
 * 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.
 * #L%
 */

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

import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static Date parseCoTDate(String dateString) throws Exception {
        if (!dateString.isEmpty()) {
            DateFormat formatter1 = new SimpleDateFormat(
                    "yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
            formatter1.setTimeZone(TimeZone.getTimeZone("Zulu"));
            DateFormat formatter2 = new SimpleDateFormat(
                    "yyyy-MM-dd'T'HH:mm:ss'Z'");
            formatter2.setTimeZone(TimeZone.getTimeZone("Zulu"));
            Date date = null;
            try {
                if (date == null)
                    date = (Date) formatter1.parse(dateString);
            } catch (ParseException ex) {
            }
            try {
                if (date == null)
                    date = (Date) formatter2.parse(dateString);
            } catch (ParseException ex) {
            }
            return date;
        }
        return null;
    }
}

Related

  1. parseBitcoin(String calendarString)
  2. parseCalendar2String(Calendar calendar)
  3. parseCalendarString(String dateTimeString)
  4. parseCDADateFormat(String xsdDate)
  5. parseCompactDate(String exp)
  6. parseDatabaseDate(String dateString)
  7. parseDD(String dateStr)
  8. parseDelayTime(String time)
  9. parseDIGTime(String timestr)