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     }
  • 相关阅读:
    Zookeeper概念学习系列之分布式事务
    序列化 反序列化 输入流 输出流
    dfs常见的配置文件中的value与description(重要)
    [转]SQL Server Reporting Services
    [转]webpack4.0.1安装问题和webpack.config.js的配置变化
    [转]Vue.js 入门教程
    [转]Webpack 入门教程
    [转]使用C#调用cmd来执行sql脚本
    [转]winform利用读取xml获取webconfig
    [转]bootstrap栅格系统的属性及使用
  • 原文地址:https://www.cnblogs.com/tian830937/p/4431942.html
Copyright © 2011-2022 走看看