Here you can find the source of dateformate(String reg, Date newdate)
public static String dateformate(String reg, Date newdate)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { static String REG = "yyyy-MM-dd"; static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(REG); public static String dateformate(String reg, Date newdate) { if (!reg.equals(REG)) { REG = reg;//from www . j ava 2s. c o m simpleDateFormat = new SimpleDateFormat(REG); } return simpleDateFormat.format(newdate); } }