Here you can find the source of standardTime(Date date)
public static Date standardTime(Date date)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date standardTime(Date date) { Calendar c = new GregorianCalendar(); c.setTime(date);/*from ww w .j a va2 s. co m*/ int minute = c.get(Calendar.MINUTE); int gewei = minute % 15; int shiwei = minute / 15 * 15; if (gewei >= 7) { gewei = 15; } else { gewei = 0; } minute = gewei + shiwei; c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } public static Date standardTime(Date date, int min) { Calendar c = new GregorianCalendar(); c.setTime(date); int minute = c.get(Calendar.MINUTE); int gewei = minute % min; int shiwei = minute / min * min; if (gewei >= min / 2) { gewei = min; } else { gewei = 0; } minute = gewei + shiwei; c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } public static Date standardTime() { return standardTime(new Date()); } public static Date standardTime(long interval) { Calendar c = new GregorianCalendar(); c.setTime(new Date()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); while (Math.abs(c.getTimeInMillis() - new Date().getTime()) > interval / 2d) { c.setTimeInMillis(c.getTimeInMillis() + interval); } return c.getTime(); } public static long getTime(String s) { return parseMysql(s).getTime(); } public static Date parseMysql(String s) { try { DateFormat fmtTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return fmtTemp.parse(s); } catch (ParseException e) { return null; } } }