DateUtil.java 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package thyyxxk.wxservice_server.utils;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. /**
  6. * @author dj
  7. */
  8. public class DateUtil {
  9. public static String formatDatetime(Date date, String pattern) {
  10. if (null == date) {
  11. date = new Date();
  12. }
  13. SimpleDateFormat sdf = new SimpleDateFormat(pattern);
  14. return sdf.format(date);
  15. }
  16. public static String[] getDatesInOneWeek() {
  17. String[] result = new String[7];
  18. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  19. Calendar calendar = Calendar.getInstance();
  20. result[0] = sdf.format(new Date());
  21. for (int i = 1; i < result.length; i++) {
  22. calendar.add(Calendar.DATE, 1);
  23. result[i] = sdf.format(calendar.getTime());
  24. }
  25. return result;
  26. }
  27. public static boolean orderValid(Date create) {
  28. long offset = System.currentTimeMillis() - create.getTime();
  29. return (offset / 1000 / 60) < 60;
  30. }
  31. }