Here you can find the source of stringToDate(final String dateTimeStr)
Parameter | Description |
---|---|
dateTimeStr | a parameter |
public static Date stringToDate(final String dateTimeStr) throws ParseException
//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); } } }