`

时间获取Clander的用法

阅读更多

/**

   * 得到几天前的时间

   * @param d

   * @param day

   * @return

   */

  public static Date getDateBefore(Date d,int day){

   Calendar now =Calendar.getInstance();

   now.setTime(d);

   now.set(Calendar.DATE,now.get(Calendar.DATE)-day);

   return now.getTime();

  }

  

  /**

   * 得到几天后的时间

   * @param d

   * @param day

   * @return

   */

  public static Date getDateAfter(Date d,int day){

   Calendar now =Calendar.getInstance();

   now.setTime(d);

   now.set(Calendar.DATE,now.get(Calendar.DATE)+day);

   return now.getTime();

  }

 

/**

*获取今天的时间的凌晨 到 23点

*

*/

private void initTime(){

Calendar cal = Calendar.getInstance();

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

this.startTime=sdf.format(cal.getTime())+" 00:00:00";

this.endTime=sdf.format(cal.getTime())+" 23:59:59";

}

//判断是不是昨天.同一天,前天 

/** 
     * @author LuoB. 
     * @param oldTime 较小的时间 
     * @param newTime 较大的时间 (如果为空   默认当前时间 ,表示和当前时间相比) 
     * @return -1 :同一天.    0:昨天 .   1 :至少是前天. 
     * @throws ParseException 转换异常 
     */  
    private int isYeaterday(Date oldTime,Date newTime) throws ParseException{  
        if(newTime==null){  
            newTime=new Date();  
        }  
               //将下面的 理解成  yyyy-MM-dd 00:00:00 更好理解点  
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
        String todayStr = format.format(newTime);  
        Date today = format.parse(todayStr);  
        //昨天 86400000=24*60*60*1000 一天  
        if((today.getTime()-oldTime.getTime())>0 && (today.getTime()-oldTime.getTime())<=86400000) {  
            return 0;  
        }  
        else if((today.getTime()-oldTime.getTime())<=0){ //至少是今天  
            return -1;  
        }  
        else{ //至少是前天  
            return 1;  
        }  
          
    }  

//判断是不是今天 

private boolean isToday(Date time){  

try {

Date nowTime=new Date();  

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

       String todayStr = format.format(nowTime);  

       Date today = format.parse(todayStr);  

       long starttime=today.getTime();

       long endtime=today.getTime()+86400000;

       if(starttime<=time.getTime() && time.getTime()<=endtime){

       return true;

       }

} catch (Exception e) {

e.printStackTrace();

}

        return false;

 

    }  

 

 
分享到:
评论

相关推荐

    日历控件clander

    Android写了一个日历小控件,请大家多多指教 这个日历控件是改一个可以滑动的scrollview嵌套一个GridView按月份展示。期间查了很多资料,呕心沥血之作。。。由于刚刚开始研究Android,希望多多给意见。

    Active Desktop Calendar 7.95 -32bit

    Active Desktop Calendar是一个可完全定制的日期定制软件,提供日期记录,任务,闹钟以及联系方法等功能,并可与桌面背景进行无缝融合以及提供足够互动性。使用者可将层中的数据进行有效组织,并在本地网络內进行...

    WdatePicker.js时间日期插件的使用方法

    本文介绍了WdatePicker.js时间插件使用,分享给大家,具体如下: 引用: 在项目中引用“plugin-clander”文件夹。 在html中引用”WdatePicker.js”即可。 [removed][removed] 1.没有对控件进行设置 &lt;input ...

    Android日历可左右活动上下定位收缩

    仿365日历,左右滑动切换月份,选择一天,上下滑动收缩

    obsidian离线插件大全

    如果无法连接社区,可以使用离线插件,在./obsidian文件加中新建plugins文件夹,然后将插件大全中对应你想要的插件解压到plugins文件夹中,重启obsidian,然后在第三方插件中关闭安全模式后就可以看到了。

    AWS-AutoScaling-Google-Calander:控制您的 AWS Autoscaling Group,从 Google Calander 获得所需的数量

    AWS-AutoScaling-Google-Calander 允许您通过更改 Google Clander 中的事件来控制 AWS AutoScaling 组中所需服务器数量的脚本第一: npm install 第二:使用config/default.yaml作为基础在config/local.yaml配置您的...

    简单日历 非常小

    简单日历 非常小

    GruidView日历源码

    GridView实现的日历,包含农历算法,

Global site tag (gtag.js) - Google Analytics