Java Parse Date Pattern YYYY parse(String string)

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

Description

Convert a string to date format

License

Open Source License

Parameter

Parameter Description
string data string

Return

date

Declaration

public static Date parse(String string) 

Method Source Code

//package com.java2s;
/**//from  w ww .  java2s  . c  o m
 * Copyright 2017 Institute of Computing Technology, Chinese Academy of Sciences.
 * Licensed under the terms of the Apache 2.0 license.
 * Please see LICENSE file in the project root for terms
 */

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

public class Main {
    /**
     * Convert a string to date format
     * @param string data string
     * @return date
     */
    public static Date parse(String string) {

        if (string == null)
            return null;
        string = string.trim();
        if (string.equals("unknown") || string.equals(""))
            return null;

        try {
            if (!"".equals(string)) {
                SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return ft.parse(string);
            } else {
                System.out.println(string);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            System.out.println("Exception string:" + string);
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. parse(String str)
  2. parse(String str)
  3. parse(String strDate)
  4. parse(String strDate)
  5. parse(String string)
  6. parse(String stringData)
  7. parse(String text)
  8. parse(String text)
  9. parse(String time)