package thyyxxk.wxservice_server.utils; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * @author dj */ public class DateUtil { public static String formatDatetime(Date date, String pattern) { if (null == date) { date = new Date(); } SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(date); } public static String[] getDatesInOneWeek() { String[] result = new String[7]; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); result[0] = sdf.format(new Date()); for (int i = 1; i < result.length; i++) { calendar.add(Calendar.DATE, 1); result[i] = sdf.format(calendar.getTime()); } return result; } public static boolean orderValid(Date create) { long offset = System.currentTimeMillis() - create.getTime(); return (offset / 1000 / 60) < 60; } }