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