Java String to Date stringToDate(final String dateTimeStr)

Here you can find the source of stringToDate(final String dateTimeStr)

Description

Transformiert einen HL7 Date/Time String in ein java.util.Date

License

Open Source License

Parameter

Parameter Description
dateTimeStr a parameter

Return

java.util.Date

Declaration

public static Date stringToDate(final String dateTimeStr)
        throws ParseException 

Method Source Code

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

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

import java.util.Date;

public class Main {
    private static final String DTM_DATE_TIME_PATTERN = "yyyyMMddHHmmss";

    /**/*from  w w  w  .ja  va 2s . c om*/
     * Transformiert einen HL7 Date/Time String in ein java.util.Date
     * 
     * @param dateTimeStr
     * @return java.util.Date
     */
    public static Date stringToDate(final String dateTimeStr)
            throws ParseException {
        if (dateTimeStr == null || dateTimeStr.length() == 0) {
            return null;
        }

        if (dateTimeStr.length() >= 14) {
            SimpleDateFormat sdf = new SimpleDateFormat(
                    DTM_DATE_TIME_PATTERN.substring(0, 14));
            return sdf.parse(dateTimeStr);
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat(
                    DTM_DATE_TIME_PATTERN.substring(0, dateTimeStr.length()));
            return sdf.parse(dateTimeStr);
        }
    }
}

Related

  1. stringArrayTODateArray(String[] dates_s, SimpleDateFormat dateformat)
  2. stringDateToDate(String str)
  3. stringDateToDate(String StrDate)
  4. stringFechaToDate(String fechaS)
  5. stringToDate(final String dateString)
  6. stringToDate(final String str, final String dateFormat)
  7. stringToDate(final String string, final String format)
  8. stringToDate(String data)
  9. StringToDate(String data)