• java中关于日期的处理


    1、某个时间与当前系统时间相差几小时(包括0.5等小数点)

      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm");

      Date rwks = simpleDateFormat.parse(“2019-10-16 18:00”);

      Date now = simpleDateFormat.parse(new Date().toLocaleString());

      long diff = rwks.getTime() - now.getTime() ;

      float hours = diff / (float)(1000 * 60 * 60);

    2、取当前系统时间的日期格式:

      Calendar dayc1 = new GregorianCalendar();

      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

      Date daystart = sdf.parse(new Date().toLocaleString());

      dayc1.setTime(daystart);

      1>取系统当天的日期:

      int towd = dayc1.get(Calendar.DATE);

      2>取系统当天加1天的日期

      dayc1.add(Calendar.DAY_OF_YEAR, 1);

      xcsj = sdf.format(dayc1.getTime());

      3>取系统当天是周几

      int w=dayc1.get(Calendar.DAY_OF_WEEK)-1;  (此方法是从周日开始)

      if(w==0) w=7;

      4>取系统当天是第几周

      int week1 = dayc1.get(Calendar.WEEK_OF_MONTH);

    3、当前时间减30分钟、1小时、2小时

      public String getxcsj(String kssj,String min){

        String xcsj = "";

        try {

          SimpleDateFormat sim = new SimpleDateFormat("HH:mm");

          Date rwkssjd = sim.parse(kssj);

          if("0.5".equals(min)){

            Date txTime = new Date(rwkssjd.getTime() - 30*60*1000);

            xcsj = sim.format(txTime);

          }else if("1".equals(min)){

            Date txTime = new Date(rwkssjd.getTime() - 60*60*1000);

            xcsj = sim.format(txTime);

          }else if("2".equals(min)){

            Date txTime = new Date(rwkssjd.getTime() - 2*60*60*1000);

            xcsj = sim.format(txTime);

          }

        } catch (Exception e) {

          log.error("获取下次提醒时间错误"+e.toString(), e);

        }

        return xcsj;

      }

  • 相关阅读:
    14.4.2 Change Buffer 延迟写
    14.4.1 Buffer Pool
    如何围绕业务特性,做企业信息化?
    如何围绕业务特性,做企业信息化?
    14.3 InnoDB Multi-Versioning InnoDB 多版本
    14.2 InnoDB and the ACID Model
    14.1.3 检查InnoDB 可用性:
    14.1.2 InnoDB表最佳实践:
    14.1.1 使用InnoDB 表的好处:
    7.5.1 Point-in-Time Recovery Using Event Times 使用Event Times 基于时间点恢复
  • 原文地址:https://www.cnblogs.com/zying3/p/11677990.html
Copyright © 2020-2023  润新知