示例#1
0
  @Test
  public void test1() {

    //
    DateUtil cal = DateUtil.now();
    cal.setTime(0, 0, 0, 0);
    int year = cal.getYear();
    int month = cal.getMonth();
    // 添加12个月的计划
    for (int i = 1; i <= 12; i++) {

      // 设置月份
      cal.setYear(year);
      cal.setMonth(month + i);

      // 从月末的一周中找出周四和周五
      cal.setDay(-7);
      int day = cal.getDay();
      for (int j = 1; j <= 7; j++) {
        cal.setDay(day + j);

        if (cal.getWeek() == 4 || cal.getWeek() == 5) {
          String str = DateUtil.format(cal.get(), "yyyy-MM-dd HH:mm:ss E");
          System.out.println("i=" + i + ", day=" + day + ", date=" + str);
        }
      }
    }
  }
示例#2
0
 public static synchronized String getBatchNo() {
   Date date = new Date();
   String nowStr = DateUtil.format(date, "yyyyMMddHHmmss");
   Random rd = new Random();
   String randomStr = "";
   for (int i = 0; i < 6; i++) {
     randomStr += rd.nextInt(10);
   }
   return nowStr + randomStr;
 }
示例#3
0
  /**
   * @author : 陈园
   * @since: 2013-8-17 上午11:30:03 功能描述:生成流水号 如20130810002 年月后的以为代表1 代表预约单 2代表自建订单 3 代表结算单 方法的参数和返回值
   * @param sum
   * @param flag
   * @return String ================================== 修改历史 修改人 修改时间 修改原因及内容
   *     <p>==================================
   */
  public static String serialCodeMax(int sum, int flag) {

    String orderNumber = DateUtil.format(new Date(), "yyyyMM");
    String strCode = String.valueOf(sum);
    strCode.length();
    for (int i = 4 - strCode.length(); i > 0; i--) {
      strCode = "0" + strCode;
    }
    return orderNumber + String.valueOf(flag) + strCode;
  }
  public static TimeSchedule2 getTimeSchedule2(String startTime, String endTime) {
    TimeSchedule2 timeSchedule = new TimeSchedule2();

    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    if (null == startTime) {

      startTime = DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd");
      startTime = startTime + " 00:00:00";

    } else {
      startTime = DateUtil.format(DateUtil.parse(startTime), "yyyy-MM-dd");
      startTime = startTime + " 00:00:00";
    }

    try {

      java.util.Date begin = dfs.parse(startTime);
      java.util.Date end = dfs.parse(endTime);
      long between = (end.getTime() - begin.getTime()) / 1000; // 除以1000是为了转换成秒

      long days = (between / 60) / (24 * 60);
      long hours = (between / 60) % (24 * 60) / 60;
      long minutes = (between / 60) % 60;
      long seconds = between - days * (24 * 60 * 60) - hours * (60 * 60) - minutes * 60;

      timeSchedule.setDates(days);
      timeSchedule.setHour(hours);
      timeSchedule.setMinute(minutes);
      timeSchedule.setSecond(seconds);

    } catch (ParseException e) {

      e.printStackTrace();
    }

    return timeSchedule;
  }
示例#5
0
  protected static void recordToErrorCounter(String cmd) {

    String today = DateUtil.format(new Date(), "yyyyMMdd");
    try {

      RedisUtil.incr(ERROR_COUNT_KEY + today);

    } catch (Exception e) {

      logger.warn("记录api返回错误请求的次数失败, today: {}", today, e);
    }

    try {

      RedisUtil.incr(ERROR_COUNT_KEY + today + ":cmd:" + cmd);

    } catch (Exception e) {

      logger.warn("记录cmd: {}, today: {} 返回错误请求的次数失败", cmd, today, e);
    }
  }
示例#6
0
 public static String formatDates(String date) {
   return isEmpty(date) ? "" : DateUtil.format(date, "yyyy-MM-dd", "yyyyMMdd");
 }
示例#7
0
 @Override
 public void serialize(
     Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
     throws IOException, JsonProcessingException {
   jsonGenerator.writeString(DateUtil.format(date));
 }