zoukankan      html  css  js  c++  java
  • java中时间的获取(二)

    java中时间的获取2

     1     /**
     2      * 获取数据库操作记录时间
     3      */
     4     public static String getOpreateDbTime() {
     5         Calendar c = Calendar.getInstance();
     6         c.setTimeInMillis(new Date().getTime());
     7         SimpleDateFormat dateFormat = new SimpleDateFormat(
     8                 "yyyy-MM-dd HH:mm:ss");
     9         return dateFormat.format(c.getTime());
    10     }
    11     
    12     /**
    13      * 获取当天日期
    14      */
    15     public static String getOpreateDay() {
    16         Calendar c = Calendar.getInstance();
    17         c.setTimeInMillis(new Date().getTime());
    18         SimpleDateFormat dateFormat = new SimpleDateFormat(
    19                 "yyyy-MM-dd");
    20         return dateFormat.format(c.getTime());
    21     }
    22     
    23     /**
    24      * 推算出两者之间的每一天的每一天
    25      */
    26     
    27     public static  List<String> geteveryDayBetweenDayLine(String maxDay,String nowDay,String sourcei){
    28         SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy-MM-dd" );
    29         List<String> list = new ArrayList<String>();
    30         try {
    31             Date date2;
    32             if(sourcei.equals("rdcj.YCSY_OILDEV_BASEDATAINFO")){
    33                 date2 = new SimpleDateFormat("yyyyMM").parse(maxDay);
    34             }else if(sourcei.equals("rdcj.YCSY_OGASRESERVOIR_BASEINFO")){
    35                 date2 = new SimpleDateFormat("MM/dd/yyyy").parse(maxDay);
    36             }else{
    37                 date2 = new SimpleDateFormat("yyyy-MM-dd").parse(maxDay);
    38             }
    39             Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(nowDay);
    40             Calendar cal = Calendar.getInstance();
    41             cal.setTime(date2); 
    42             while(cal.getTime().compareTo(date1)<=0){ 
    43             cal.add(Calendar.DAY_OF_MONTH,1);
    44              list.add(sdf.format(cal.getTime()));
    45             }
    46         } catch (ParseException e) {
    47             // TODO Auto-generated catch block
    48             e.printStackTrace();
    49         }
    50         return list;
    51     }
  • 相关阅读:
    vue-动画
    vue笔记-路由,组件
    自定义键盘信息
    自定义指令
    vue-笔记2
    轻松搭建基于 Serverless 的文档图片在线转换服务
    轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
    一小时快速搭建基于阿里云容器服务-Kubernetes的Web应用
    阿里云正式推出内容平台“云栖号”:全面助力企业和个人上云决策
    云原生安全-更安全的密文管理 Vault on ACK
  • 原文地址:https://www.cnblogs.com/tian830937/p/4431942.html
Copyright © 2011-2022 走看看