Java Date to String dateToString(final Date date)

Here you can find the source of dateToString(final Date date)

Description

Transformiert java.util.Date in ein HL7 String

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String dateToString(final Date date) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

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

    /**// w ww . j a va 2  s  . c  o m
     * Transformiert java.util.Date in ein HL7 String
     * 
     * @param date
     * @return
     */
    public static String dateToString(final Date date) {
        if (date == null) {
            return null;
        }
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        String pattern = DTM_DATE_TIME_PATTERN;
        if (cal.get(Calendar.SECOND) == 0) {
            pattern.substring(0, pattern.length() - 2);
        }
        if (cal.get(Calendar.MINUTE) == 0) {
            pattern.substring(0, pattern.length() - 2);
        }
        if (cal.get(Calendar.HOUR) == 0) {
            pattern.substring(0, pattern.length() - 2);
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(cal.getTime());
    }
}

Related

  1. DateToString(Date fecha, String formato)
  2. dateToString(Date pd_fecha)
  3. dateToString(Date pDate, String pFormat)
  4. dateToString(Date pdttValue, String pstrDateFormat)
  5. DateToString(Date thisdate, Locale locale)
  6. dateToString(final Date value, final boolean utc)
  7. dateToString(java.util.Date currdate, String strFormat)
  8. dateToString(String date, String format)
  9. dateToString(String str, DateTimeFormatter dateTimeFormatter)