Here you can find the source of dateFormater(String dataStr, String dataFormat)
public static Date dateFormater(String dataStr, String dataFormat)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static Date dateFormater(String dataStr, String dataFormat) { DateFormat dateFormat = new SimpleDateFormat(dataFormat, Locale.ENGLISH); Date date = null;/*from w ww .j a v a 2 s . c o m*/ try { date = dateFormat.parse(dataStr); } catch (ParseException e) { e.printStackTrace(); } return date; } public static String dateFormater(Date date, String dataFormat) { DateFormat formater = new SimpleDateFormat(dataFormat, Locale.ENGLISH); String dateStr = null; dateStr = formater.format(date); return dateStr; } }