Here you can find the source of getDateFormat(String dateStr)
public static DateFormat getDateFormat(String dateStr)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; public class Main { private static DateFormat fmtDate = new SimpleDateFormat("yyyy-MM-dd"); private static DateFormat fmtTime = new SimpleDateFormat("HH:mm:ss"); private static DateFormat fmtDT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static DateFormat getDateFormat(String dateStr) { int pos1 = dateStr.indexOf("-"); int pos2 = dateStr.indexOf(":"); DateFormat dt = null;/* w w w .j a v a 2 s . c om*/ if (pos1 != -1 && pos2 != -1) { dt = fmtDT; } else if (pos1 != -1 && pos2 == -1) { dt = fmtDate; } else if (pos1 == -1 && pos2 != -1) { dt = fmtTime; } else { dt = fmtDate; } return dt; } }