Java Date Parse convertStringToDate(String arg)

Here you can find the source of convertStringToDate(String arg)

Description

Converts string to Date using Default date format

License

Open Source License

Parameter

Parameter Description
arg string to convert

Return

Date

Declaration

private static Date convertStringToDate(String arg) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    /**/*from   ww w.  ja va  2  s .  co m*/
     * Converts string to Date using Default date format
     * 
     * @param arg
     *            string to convert
     * @return Date
     */
    private static Date convertStringToDate(String arg) {

        DateFormat df = getIsoFormat();

        Date d = null;
        try {
            d = df.parse(arg);
        } catch (ParseException e) {
            //
        }

        return d;
    }

    /**
     * Returns ISO DataFormat 'yyyy-MM-dd'T'HH:mm:ss.SSS'
     * 
     * @return ISO DateFormat
     */
    public static DateFormat getIsoFormat() {
        SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); //$NON-NLS-1$
        isoFormat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
        return isoFormat;
    }
}

Related

  1. convertIntToDate(int date)
  2. convertIntToDatePattern2(int date)
  3. convertLongToDate(final long time)
  4. convertStringToDate(String aMask, String strDate)
  5. convertStringToDate(String aMask, String strDate)
  6. convertStringToDate(String data)
  7. convertStringToDate(String date)
  8. convertStringToDate(String date)
  9. convertStringToDate(String date)