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. C#-WebForm-点击网页中的按钮后跳转到其他页面是怎么实现的?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Android基础总结(九)

    多媒体概念(了解) 文字.图片.音频.视频 计算机图片大小的计算(掌握) 图片大小 = 图片的总像素 * 每个像素占用的大小 单色图:每个像素占用1/8个字节 16色图:每个像素占用1/2个字节 25 ...

  3. ABBA BABA statistics

    The ABBA BABA statistics are used to detect and quantify an excess of shared derived alleles, which ...

  4. angualr 实现tab选项卡功能

    tab.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  5. dotnet获取PDF文件的页数

    #region 获取PDF文件的页数 private int BytesLastIndexOf(Byte[] buffer, int length, string Search) { if (buff ...

  6. 利用django创建一个投票网站(二)

    创建你的第一个 Django 项目, 第二部分 这一篇从第一部分(zh)结尾的地方继续讲起.本节我们将继续写 Web 投票应用,并主要关注 Django 提供的自动生成的管理页面(admin site ...

  7. NOIp 11.11/12

    最后一场比较正式的NOIp模拟赛,写一发小总结.题目没什么好说的,大部分很简单,先贴一下代码. 1111 T1 //string //by Cydiater //2016.11.11 #include ...

  8. BZOJ3879: SvT

    后缀数组裸题,每次的查询单调栈扫一遍就完了.为什么要写虚后缀树= =后缀数组不是自带虚树的结构么= = #include<cstdio> #include<algorithm> ...

  9. pdf在线处理网站

    https://smallpdf.com/unlock-pdf

  10. K-Means clusternig example with Python and Scikit-learn(推荐)

    https://www.pythonprogramming.net/flat-clustering-machine-learning-python-scikit-learn/ Unsupervised ...