Java Parse Date Pattern YYYY parseAscTime(String date)

Here you can find the source of parseAscTime(String date)

Description

Parses an ASC formatted date string into a DateTime object

License

Apache License

Parameter

Parameter Description
date The string Asc format.

Return

A DateTime object representing the date in the string, or null if the string isn't properly formatted.

Declaration

public static DateTime parseAscTime(String date) 

Method Source Code


//package com.java2s;
/*/*  w  w  w  . ja  va  2  s  .co  m*/
 * Copyright 2012 Johns Hopkins University
 *
 * 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.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

public class Main {
    private static final String ASC_FORMAT = "EEE MMM dd HH:mm:ss yyyy";

    /**
     * Parses an ASC formatted date string into a DateTime object
     * @param date The string Asc format.
     * @return A DateTime object representing the date in the string, or null if the string isn't properly formatted. 
     */
    public static DateTime parseAscTime(String date) {
        DateTime dateTime = null;
        try {

            Date parsedDate = getDateFormat(ASC_FORMAT).parse(date);
            dateTime = new DateTime(parsedDate.getTime()).withZone(DateTimeZone.forID("GMT"));
        } catch (ParseException e) {
            //The string was not formatted correctly, ensure null is returned
            dateTime = null;
        }
        return dateTime;
    }

    private static DateFormat getDateFormat(String format) {
        DateFormat fmt = new SimpleDateFormat(format);
        fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
        return fmt;
    }
}

Related

  1. parse1(String DateString, String dateTimeSeparator)
  2. parse2DateString(String date)
  3. parse_default(String time)
  4. parseApplePurchaseDate(String dateStr)
  5. parseArgument(String textDate)
  6. parseAsDateTime(String date)
  7. parseAtomDate(String date_str)
  8. parseBingDate(String dateString)
  9. parseBitcoin(String calendarString)