Java Parse Date Pattern YYYY parse(String ds)

Here you can find the source of parse(String ds)

Description

Parse the date string using the default date format.

License

Apache License

Parameter

Parameter Description
ds - Date String

Exception

Parameter Description
Exception an exception

Declaration

public static final Date parse(String ds) throws Exception 

Method Source Code

//package com.java2s;
/**//w w  w.  j  a v  a2 s.c o m
 * Copyright 2012 Subho Ghosh (subho dot ghosh at outlook dot com)
 * 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.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static final String _DEFAULT_DATE_FORMAT_ = "MM-dd-yyyy HH:mm:ss";

    /**
     * Parse the date string using the default date format.
     * 
     * @param ds
     *            - Date String
     * @return
     * @throws Exception
     */
    public static final Date parse(String ds) throws Exception {
        return parse(ds, _DEFAULT_DATE_FORMAT_);
    }

    /**
     * Parse the date string using the specified date format.
     * 
     * @param ds
     *            - Date String
     * @param format
     *            - Date Format
     * @return
     * @throws Exception
     */
    public static final Date parse(String ds, String format) throws Exception {
        DateFormat formatter = new SimpleDateFormat(format);
        return (Date) formatter.parse(ds);
    }
}

Related

  1. parse(String DateString)
  2. parse(String dateString)
  3. parse(String dateString)
  4. parse(String dateString, String dateFormat)
  5. parse(String dateText)
  6. parse(String format, String val)
  7. parse(String input)
  8. parse(String original)
  9. parse(String param)