Java tutorial
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { /** * format Data like "yyyy-MM-dd" * * @param date * @return */ public static String parseDate(Date date) { if (date != null) { return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(date); } else { return ""; } } /** * parse date using default pattern yyyy-MM-dd * * @param strDate * @return */ public static final Date parseDate(String strDate) { Date date = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); date = dateFormat.parse(strDate); return date; } catch (Exception pe) { return null; } } }