Here you can find the source of formatCharDateYMD(String str)
public static Date formatCharDateYMD(String str)
//package com.java2s; import java.sql.Date; import java.text.*; public class Main { public static final String DEFAULT_DATE_YMD_FORMAT = "yyyy-MM-dd"; public static Date formatCharDateYMD(String str) { return formatCharDateYMD(str, DEFAULT_DATE_YMD_FORMAT); }// ww w .j av a 2 s . c o m public static Date formatCharDateYMD(String str, String format) { if (str == null || str.trim().length() == 0) { return null; } if (format == null) { throw new IllegalArgumentException("The value of an argument is inaccurate."); } SimpleDateFormat sdf = new SimpleDateFormat(format); ParsePosition pos = new ParsePosition(0); java.util.Date date = sdf.parse(str, pos); if (date == null) { return null; } return new Date(date.getTime()); } public static Date formatCharDateYMD(String yy, String mm, String dd) { if (yy == null || mm == null || dd == null || yy.trim().length() == 0 || mm.trim().length() == 0 || dd.trim().length() == 0) { return null; } return formatCharDateYMD(yy + "-" + (mm != null && mm.length() == 1 ? "0" + mm : mm) + "-" + (dd != null && dd.length() == 1 ? "0" + dd : dd)); } }