Here you can find the source of formatTime(Date now, String pattern)
public static String formatTime(Date now, String pattern)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String formatTime(Date now, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(now); }// w ww . j a va 2 s. c o m public static String formatTime(Date now, String pattern, int tensMinutes) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmm"); String timestamp = sdf.format(now); int len = timestamp.length(); String dateHour = timestamp.substring(0, len - 2); int minute = Integer.valueOf(timestamp.substring(len - 2)) / tensMinutes * (tensMinutes / 10); return dateHour + minute + "0"; } }