import java.util.Date;
import java.text.SimpleDateFormat; public class WriteForBlog
{
static private int beforeDays = 8; // Use this vaule to judge the start date within 7 days.
static private long beforeSeconds = beforeDays * 24 * 60 * 60 * 1000; public static void main(String[] args)
{
String strTime = "2016-10-28";
if(isNewzt(strTime, beforeSeconds))
{
System.out.println("7 days old");
}
else
{
System.out.println("more than 7 days");
}
} private static boolean isNewzt(String theStrTime, long beforeDays)
{
boolean flag = false;
if("0".equals(theStrTime))
{
return flag;
} try
{
Date tDat = StrToDate(theStrTime, "");
long thm = tDat.getTime();
long chm=System.currentTimeMillis();
if(thm + beforeDays >=chm)
{
flag = true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
return flag;
} private static Date StrToDate(String str, String formatStr)
{
if (null == formatStr || "".equals(formatStr))
{
formatStr = "yyyy-MM-dd";
} SimpleDateFormat format = new SimpleDateFormat(formatStr);
Date date = null;
try
{
date = format.parse(str);
}
catch(Exception e)
{
e.printStackTrace();
}
return date;
} }

忘记是参考哪个blog的。

Java 判断时间是否在指定天数之内的更多相关文章

  1. JAVA判断时间是否在时间区间内

    package com.liying.tiger.test; import java.text.ParseException; import java.text.SimpleDateFormat; i ...

  2. java判断时间大小

    //构造日期格式yyyy-MM-NN SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date d ...

  3. java判断时间是否是今天

    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); Date d1=format.parse(FHavetime ...

  4. java判断时间为上午,中午,下午,晚上,凌晨

    public static void main(String[] args) { Date date = new Date(); SimpleDateFormat df = new SimpleDat ...

  5. Android判断当前系统时间是否在指定时间的范围内(免消息打扰)

    /** * 判断当前系统时间是否在指定时间的范围内 * * @param beginHour * 开始小时,例如22 * @param beginMin * 开始小时的分钟数,例如30 * @para ...

  6. Java判断一个时间是否在另一个时间段内

    需求:当时间在凌晨0点至0点5分之间程序不执行. 也就是实现判断当前时间点是否在00:00:00至00:05:00之间 方法: Java代码 : /** * 判断时间是否在时间段内 * * @para ...

  7. java获取前一天时间SimpleDateFormat,java判断某个时间段

    java获取前一天时间SimpleDateFormat SimpleDateFormat predf = new SimpleDateFormat("yyyy-MM-dd"); D ...

  8. JAVA时间进行比较和转换,时间加减得到天数

    转自:https://blog.csdn.net/iteye_8535/article/details/82246006 JAVA时间进行比较和转换,时间加减得到天数 1. 把时间类型的字符串转为DA ...

  9. Java丨时间判断谁前谁后

    直奔主题: String date_str1 = "2016-06-02 23:03:123"; String date_str2 = "2016-06-03 03:03 ...

随机推荐

  1. 使用DataTable更新数据库

    简例: string connStr = string.Format("Driver={1}Microsoft Access Driver (*.mdb){2};DBQ={0};" ...

  2. 关于js中this关键字的补充

    前面: 前面虽然综合了网络上不少大牛的心得,但感觉还是意犹未尽,为了彻底搞清楚js中this的相关知识,决定再写一篇.个人觉得,在技术上,除非钻到细枝末节,否则很难达至非常高的水平. 补充1: 无法重 ...

  3. Cordova应用程序修改启动画面或者Icon

    1)  制作启动画面图片或icon ionic resources //同时生成icon和splash ionic resources --icon //只生成icon ionic resources ...

  4. HTML学习笔记——标签(二)

    标签十二:<ul>标签 语义:是没有前后顺序的信息列表 语法: <ul> <li>信息</li> <li>信息</li> ... ...

  5. 阿里云免费申请免费SSL证书

    随着互联网的不断进步与发展,对于网站与数据的安全性要求也越来越高,原本的HTTP明文传输已经不被信任,https逐渐被关注,从谷歌.火狐浏览器将对HTTP明文页面标记"不安全",到 ...

  6. JUC学习笔记--Atomic原子类

    J.U.C 框架学习顺序 http://blog.csdn.net/chen7253886/article/details/52769111 Atomic 原子操作类包 Atomic包 主要是在多线程 ...

  7. C#基础:飞行棋游戏

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. Python学习总结 01 配置环境

    1 查看python的版本 ubuntu16.04 LTS系统下默认安装了python2.7.12 和python3.5.2, 她们在/usr/bin/下可以找到, 默认用python2.7.8 1) ...

  9. EditPlus-CN使用总结

    EditPlus-CN使用总结 --------------- 注册名:Free User注册码:6AC8D-784D8-DDZ95-B8W3A-45TFA ---------------- 1.如何 ...

  10. webapi8