判断是不是cron表达式每天0点

当前位置:
如何通过Cron表达式来获取最近运行时间?
猜你喜欢的文章
如何通过Cron表达式来获取最近运行时间?
来源:网络整理&&&&&时间: 14:38:40&&&&&关键词:
关于网友提出的“ 如何通过Cron表达式来获取最近运行时间?”问题疑问,本网通过在网上对“ 如何通过Cron表达式来获取最近运行时间?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 如何通过Cron表达式来获取最近运行时间?
描述:调度quarzt
quarzt.net大家都很熟悉了.代码也很简单.不过这个Cron表达式确实是比较费劲.
不过还好&由于网上有那种"表达式生成器"让我们节省了很多时间..比如下面的地址.
http://cron.qqe2.com/
随意百度出来的&都差不多是这个样子.不过这个网站比较特殊,他下面会根据你的表达式来返回你最近5次的运行时间.
比如&我设置了
0&55&23&1,11,21&*&?&
每月的1号11号21号的23点55.
那么他在下面会返回引用最近5次运行时间:
F12后发现他自己请求了自己的一个接口
http://cron.qqe2.com/CalcRunTime.ashx?Cr />
他这里的代码是如何实现的呢?
因为5次运行时间太少了&我想要10次..或者更多&因为我的表达式比较复杂,.5条记录还看不出来对与错...解决方案1://
&&&&&&&&//&摘要:
&&&&&&&&//&&&&&Gets&the&next&time&to&fire&after&the&given&time.
&&&&&&&&//
&&&&&&&&//&参数:
&&&&&&&&//&&&afterTime:
&&&&&&&&//&&&&&The&time&to&compute&from.
&&&&&&&&protected&DateTimeOffset?&GetTimeAfter(DateTimeOffset&afterTime);
&&&&&&&&//
&&&&&&&&//&摘要:
&&&&&&&&//&&&&&NOT&YET&IMPLEMENTED:&Returns&the&time&before&the&given&time&that&this&Quartz.ICronTrigger
&&&&&&&&//&&&&&will&fire.
&&&&&&&&//
&&&&&&&&//&参数:
&&&&&&&&//&&&date:
&&&&&&&&//&&&&&The&date.
&&&&&&&&protected&DateTimeOffset?&GetTimeBefore(DateTimeOffset?&date);
满满的都是现成的方法啊
解决方案2:
Quartz.Impl.Triggers.CronTriggerImpl看起来可以直接用,如果不行的话,那就找下源代码,看内部是怎么处理的public&CronTriggerImpl(string&name,&string&group,&string&cronExpression);
以上介绍了“ 如何通过Cron表达式来获取最近运行时间?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/4310988.html
上一篇: 下一篇:QuartZ Cron表达式详解 - 简书
QuartZ Cron表达式详解
本文包含如下内容
CronTrigger简介
Cron 表达式
Cron表达式可选的值
Cron表达式的配置规则
Cron表达式范例:
*/5 * * * * ?
每隔5秒执行一次
0 */1 * * * ?
每隔1分钟执行一次
0 0 23 * * ?
每天23点执行一次
0 0 1 * * ?
每天凌晨1点执行一次:
0 0 1 1 * ?
每月1号凌晨1点执行一次
0 0 23 L * ?
每月最后一天23点执行一次
0 0 1 ? * L
每周星期天凌晨1点实行一次
0 26,29,33 * * * ?
在26分、29分、33分执行一次
0 0 0,13,18,21 * * ? 每天的0点、13点、18点、21点都执行一次
Cron 表达式
Cron表达式由7个部分组成,各部分用空格隔开,例如0 0 12 ? * WED(每星期三下午12:00 执行)
Cron表达式的7个部分从左到右代表的含义如下
Seconds Minutes Hours Day-of-Month Month Day-of-Week Year
其中Year是可选的
Cron表达式可选的值
秒:数字0-59
分:数字0-59
时 :数字0-23
Day-of-Month
月中的几号 :可以用数字1-31 中的任一一个值,但要注意一些特别的月份
一年中的几月:可以用0-11 或用字符串
“JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC” 表示
Day-of-Week
每周:数字1-7(1 = 星期日),或用字符口串“SUN, MON, TUE, WED, THU, FRI and SAT”
允许的特殊字符
, - * ? / L W C
1-12 or JAN-DEC
1-7 or SUN-SAT
, - * ? / L C #
年 (可选字段)
Cron中的符号
* :代表整个时间段.
/ :表示每多长时间执行一次
0/15表示每隔15分钟执行一次,“0”表示为从“0”分开始;
3/20表示每隔20分钟执行一次,“3”表示从第3分钟开始执行
? :表示每月的某一天,或第几周的某一天
“6L”表示“每月的最后一个星期五”
W:表示为最近工作日
如“15W”放在每月(day-of-month)字段上表示为“到本月15日最近的工作日”
#:是用来指定“的”每月第n个工作日
"6#3"或者"FRI#3":在每周(day-of-week)中表示“每月第三个星期五”
问号(?)就是用来对日期和星期字段做互斥的,问号(?)的作用是指明该字段‘没有特定的值’,星号(*)和其它值,比如数字,都是给该字段指明特定的值,而星号(*)代表所有,在天时表示每一天。
“?”字符:表示不确定的值
“,”字符:指定数个值
“-”字符:指定一个值的范围
“/”字符:指定一个值的增加幅度。n/m表示从n开始,每次增加m
“L”字符:用在日表示一个月中的最后一天,用在周表示该月最后一个星期X
“W”字符:指定离给定日期最近的工作日(周一到周五)
“#”字符:表示该月第几个周X。6#3表示该月第3个周五
本文包含如下内容 CronTrigger简介Cron 表达式Cron表达式可选的值Cron表达式的配置规则Cron表达式范例: Cron 表达式 Cron表达式由7个部分组成,各部分用空格隔开,例如0 0 12 ? * WED(每星期三下午12:00 执行)Cron表达式的...
时间格式: s& m &h &d& m& w(?)& y(?)
分别对应: 秒&分&小时&日&月&周&年, 1.每天什么时候执行: 0 59 23 * * ?: 如下为每天23:59:00开始执行 0 1,2,3 11,12 * * ? : 每天11:01,11:02,...
几个正则表达式编辑器 Debuggex :https://www.debuggex.com/ PyRegex:http://www.pyregex.com/ Regexper:http://www.regexper.com/ 正则表达式是一种查找以及字符串替换操作。正则表达...
国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿: 前言: 排版 by Dr_Ting公众号:庭说移步 tingtalk.me 获得更友好的阅读体验 Q/GDW XXXX-201X《面向对象的用电信息数据交换协议》是根据《国家...
“请问您要哪种咖啡?” “爱尔兰咖啡。” 爱尔兰咖啡,名字里就带着一阵威士忌浓烈的熏香,一丝成熟的忧郁…… 小心,咖啡喝多了会醉,都柏林这地方呆多了也会醉! 醉了,就索性多呆几天吧,手持一张“翡翠卡”或“罗弗票”,就可以无限制地乘坐火车数天往返各地。 爱尔兰铁路系统档次与欧...
1.收获 学业 春节开学之后的一个学期结束了各门课程,顺利通过了各科考试; 用两个月时间考到了驾照; 做了一些预实验,暑假开学之前做完了测总磷的实验; 经过了开题答辩; 暑假和北大的三位同学去四川参加农村环境调研,获得了优秀团队奖…… 兼职 年初的时候在影院场务兼职,认识了...
周日,风停了,可以开心地出游了。 吃过早饭,趁着凉快赶紧出发。 朝阳公园停车,骑车到团结湖东门。 公园已经免费了。 进门去码头,趁着早,租一条船。 开着电瓶船,周围都已经是高楼大厦了。 碧波荡漾的湖面,非常漂亮。 喵也来学学开船,上次来的时候才2岁,抱...
身体是否健康可以从人体的多方面表现出来,但是你知道怎么看吗?现在就为大家带来史上最全的—— 《身体“缺啥补啥”对照表》 一查就能知道自己缺什么, 自己的身体自己掌握, 一定要收好咯! 一看“头”:健康从头开始 1.头发发黄、发焦,补蛋白质; 2.头发疏稀无光,补蛋白质、维生...博客分类:
java 中,如何把日期(时间点,不是时间段)转化为cron表达式呢?
我觉得这个功能是很常用的,结果在网上竟然没有找到,真是奇怪了?!
直接给代码:
* @param date
* @param dateFormat : e.g:yyyy-MM-dd HH:mm:ss
public static String formatDateByPattern(Date date,String dateFormat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* convert Date to cron ,eg.
"0 06 10 15 1 ? 2014"
* @param date
public static String getCron(java.util.Date
String dateFormat="ss mm HH dd MM ? yyyy";
return formatDateByPattern(date, dateFormat);
public void test_getCron(){
String cron=TimeHWUtil.getCron(new Date());
System.out.println(cron);
运行结果:
关于cron,请参阅:
A cron expression is a string comprised of 6 or 7 fields separated by white space. Fields can contain any of the allowed values, along with various combinations of the allowed special characters for that field. The fields are as follows:
Field Name
Allowed Values
Allowed Special Characters
Day of month
, - * ? / L W
1-12 or JAN-DEC
Day of week
1-7 or SUN-SAT
, - * ? / L #
So cron expressions can be as simple as this: * * * * ? *
or more complex, like this: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI
Here are some full examples:
**Expression**
**Meaning**
0 0 12 * * ?
Fire at 12pm (noon) every day
0 15 10 ? * *
Fire at 10:15am every day
0 15 10 * * ?
Fire at 10:15am every day
0 15 10 * * ? *
Fire at 10:15am every day
0 15 10 * * ? 2005
Fire at 10:15am every day during the year 2005
0 * 14 * * ?
Fire every minute starting at 2pm and ending at 2:59pm, every day
0 0/5 14 * * ?
Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day
0 0/5 14,18 * * ?
Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
0 0-5 14 * * ?
Fire every minute starting at 2pm and ending at 2:05pm, every day
0 10,44 14 ? 3 WED
Fire at 2:10pm and at 2:44pm every Wednesday in the month of March.
0 15 10 ? * MON-FRI
Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 15 * ?
Fire at 10:15am on the 15th day of every month
0 15 10 L * ?
Fire at 10:15am on the last day of every month
0 15 10 L-2 * ?
Fire at 10:15am on the 2nd-to-last last day of every month
0 15 10 ? * 6L
Fire at 10:15am on the last Friday of every month
0 15 10 ? * 6L
Fire at 10:15am on the last Friday of every month
0 15 10 ? * 6L
Fire at 10:15am on every last friday of every month during the years , 2004 and 2005
0 15 10 ? * 6#3
Fire at 10:15am on the third Friday of every month
0 0 12 1/5 * ?
Fire at 12pm (noon) every 5 days every month, starting on the first day of the month.
0 11 11 11 11 ?
Fire every November 11th at 11:11am.
Pay attention to the effects of '?' and '*' in the day-of-week and day-of-month fields!
TimeHWUtil 源代码如下
package com.time.
import com.common.bean.TimeL
import com.common.util.ReflectHWU
import com.common.util.SystemHWU
import com.string.widget.util.ValueW
import java.sql.T
import java.text.ParseE
import java.text.SimpleDateF
import java.util.C
import java.util.D
import java.util.L
import java.util.L
import java.util.regex.P
* http://hw.iteye.com/blog/2225264
* @author huangweii
public class TimeHWUtil {
* yyyy-MM-dd HH:mm:ss
public static final String yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
public static final String YYYYMMDDHHMM = "yyyy-MM-dd HH:mm";
public static final String YYYYMMDDHHMM_ZH = "yyyy年MM月dd HH点mm分";
public static final String YYYYMMDDHHMMSS_ZH="yyyy年MM月dd日 HH点mm分ss秒";
public static final String yyyyMMdd = "yyyy-MM-dd";
* 没有中划线
public static final String YYYYMMDD_NO_LINE = "yyyyMMdd";
public static final String YYYYMMDD_WITH_DOT = "yyyy.MM.dd";
private TimeHWUtil() {
throw new Error("Don't let anyone instantiate this class.");
* yyyy-MM-dd HH:mm:ss
* @param timestamp
public static String formatDateTime(Timestamp timestamp) {// format date
// ,such as
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
* @param Millisecond :毫秒数
public static String formatDateTime(long Millisecond) {
Timestamp timestamp=new Timestamp(Millisecond);
return formatDateTime(timestamp);
* yyyy-MM-dd HH:mm:ss
* @param date
public static String formatDateTime(Date date) {// format date ,such as
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);
String formatStr =
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
if (date != null) {
formatStr = sdf.format(date);
return formatS
* 格式化当前时间,格式为:yyyy-MM-dd HH:mm:ss
public static String formatDateTime() {
return formatDateTime(null);
* yyyy-MM-dd
* @param timestamp
public static String formatDate(Timestamp timestamp) {// format date ,such
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
* yyyy-MM-dd
* @param date
public static String formatDate(Date date) {// format date ,such as
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String formatDateZh(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String formatDateZh(Timestamp timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
* @param formatStr
format : yyyy-MM-dd HH:mm:ss
* @throws ParseException
public static Timestamp getTimestamp4Str(String formatStr)
throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);
return new Timestamp(sdf.parse(formatStr).getTime());
* @param date
format : yyyy-MM-dd HH:mm:ss
public static Timestamp getTimestamp4Date(Date date) {
if (date == null) {
date = new Date();
return new Timestamp(date.getTime());
public static Date getDate4Str(String formatStr) throws ParseException {
String format=
if(formatStr.length()&10){
format=yyyyMMddHH
format=yyyyMM
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.parse(formatStr);
public static Date getUSDate4Str(String dateStr){
SimpleDateFormat sdf = new SimpleDateFormat("MMM d HH:mm:ss", Locale.US);
Date date= sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
* format : yyyy年MM月dd日 HH点mm分ss秒
* @param timestamp
public static String formatTimestampZH(Timestamp timestamp) {
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDDHHMMSS_ZH);
return sdf.format(timestamp);
public static String formatDateTimeZH(Date date) {
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDDHHMMSS_ZH);
return sdf.format(date);
* 比较是否过期 true:过期,不能正常使用 &br&false:正常使用
* @param timestamp
public static boolean compareToTimestamp(Timestamp timestamp) {
return timestamp.before(new java.util.Date());
* 比较是否过期 true:过期,不能正常使用 &br&false:正常使用
* @param date
: java.util.Date
public static boolean compareToDate(Date date) {
return date.before(new java.util.Date());
public static Timestamp getTimestampAfter(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
return new Timestamp(now.getTimeInMillis());
// public static java.util.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();
public static Timestamp getTimestampBefore(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
return new Timestamp(now.getTimeInMillis());
* @param d
:Base Date
* @param minutes
:Minutes delayed
public static java.util.Date getDateAfterMinute(Date d, int minutes) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) + minutes);
return now.getTime();
* @param d : 基准日期
* @param day : 几天前
* @throws ParseException
public static java.util.Date getDateBefore(String d, int day) throws ParseException {
java.util.Date date=getDate4Str(d);
return getDateBefore(date, day);
* @param d : 基准时间
* @param day : 几天前
public static java.util.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 second : 秒
public static java.util.Date getDateBySecond(long second){
Date date=new Date(second*1000);
* 返回秒(不是毫秒)
* @param d
* @param day
public static long getSecondBefore(Date d, int day) {
return getDateBefore(d, day).getTime()/1000;
* @param d : 基准时间
* @param day
* @throws ParseException
public static long getSecondBefore(String d, int day) throws ParseException {
java.util.Date date=getDate4Str(d);
return getDateBefore(date, day).getTime()/1000;
public static java.util.Date getDateBeforeMinute(Date d, int minutes) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) - minutes);
return now.getTime();
* @param d
* @param hour : 小时
public static java.util.Date getDateBeforeHour(Date d, int hour) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.HOUR, now.get(Calendar.HOUR) - hour);
return now.getTime();
* get current datetime
public static Timestamp getCurrentTimestamp() {
return new Timestamp(System.currentTimeMillis());
* 获取当前时间,并且格式化为"yyyy-MM-dd HH:mm:ss"
public static String getCurrentFormattedTime(){
return formatDateTime(new Date());
* @return : 当前时间的毫秒数
public static long getCurrentTimeLong(){
return new Date().getTime();
* @return : 当前时间的秒数
public static long getCurrentTimeSecond(Date date){
if(ValueWidget.isNullOrEmpty(date)){
date=new Date();
return date.getTime()/1000;
* 当前时间的秒数
public static long getCurrentTimeSecond(){
return getCurrentTimeSecond(null);
* Get current sql data
public static java.sql.Date getCurrentSQLDate(){
return new java.sql.Date(System.currentTimeMillis());
public static Calendar getCalendar() {
Calendar c = Calendar.getInstance();
public static Calendar getCalendar(Date date) {
Calendar c = Calendar.getInstance();
if(ValueWidget.isNullOrEmpty(date)){
date=new Date();
c.setTime(date);
* _yy_MM_dd_HH_mm_ss_
* @param date
public static String formatTimestamp2(Date date) {// format date ,such as
SimpleDateFormat sdf = new SimpleDateFormat("_yy_MM_dd_HH_mm_ss_");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* @param d
:Base Date
* @param day
:Delayed days
public static java.util.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();
public static java.util.Date getDateAfterByYear(Date d, int year) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.YEAR, now.get(Calendar.YEAR) + year);
return now.getTime();
* 以月为单位
* @param d
* @param month
public static java.util.Date getDateAfterByMonth(Date d, int month) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.MONTH, now.get(Calendar.MONTH) + month);
return now.getTime();
* 以小时为单位
* @param d
* @param hour
public static java.util.Date getDateAfterByHour(Date d, int hour) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.HOUR, now.get(Calendar.HOUR) + hour);
return now.getTime();
public static java.util.Date getDateAfterByHour(String dateStr, int hour) throws ParseException {
Date d = getDate4Str(dateStr);
return getDateAfterByHour(d, hour);
* Determine whether date is valid, including the case of a leap year
* @param date
YYYY-mm-dd
public static boolean isDate(String date) {
StringBuffer reg = new StringBuffer(
"^((\\d{2}(([0])|([13579][26]))-?((((0?");
reg.append("[13578])|(1[02]))-?((0?[1-9])|([1-2][0-9])|(3[01])))");
reg.append("|(((0?[469])|(11))-?((0?[1-9])|([1-2][0-9])|(30)))|");
reg.append("(0?2-?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][12");
reg.append("35679])|([189]))-?((((0?[13578])|(1[02]))");
reg.append("-?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))");
reg.append("-?((0?[1-9])|([1-2][0-9])|(30)))|(0?2-?((0?[");
reg.append("1-9])|(1[0-9])|(2[0-8]))))))");
Pattern p = Pattern.compile(reg.toString());
return p.matcher(date).matches();
* @param dateStr
public static boolean isShortDate(String dateStr) {
boolean isRegexRight = dateStr.matches("[\\d]{8}");
if (!isRegexRight) {
Date date = parseDateByPattern(dateStr, YYYYMMDD_NO_LINE);
if (date == null) {
* format Date
* @param date
* @param formatString
public static String formatDate(Date date, String formatString) {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.format(date);
} catch (Exception ex) {
return "";
public static String formatTimestamp_noSecond(Timestamp timestamp) {// format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String formatTimeStr =
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
public static String formatTimestampShortStr(Timestamp timestamp) {// format
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
public static String formatDateShortZh(Timestamp timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
public static String formatDateShortZh(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* "yyyy-MM-dd"
* @param date
public static String formatDateShortEN(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String formatDateZhAll(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* 获取当前的时间
* @return : 格式化之后的字符串,例如" 11:07:35"
public static String getCurrentDateTime(){
return formatDateTime(new Date());
public static String getMiniuteSecond(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(date)){
date=new Date();
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String getMiniuteSecondZH(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("mm分ss秒");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String getCurrentMiniuteSecond() {
Date date=new Date();
return getMiniuteSecond(date);
public static String getCurrentMiniuteSecondZH() {
Date date=new Date();
return getMiniuteSecondZH(date);
* @param date
* @param dateFormat : e.g:yyyy-MM-dd HH:mm:ss
public static String formatDateByPattern(Date date,String dateFormat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* @param dateStr
* @param dateFormat
public static Date parseDateByPattern(String dateStr,String dateFormat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
* convert Date to cron ,eg.
"0 06 10 15 1 ? 2014"
* @param date
public static String getCron(java.util.Date
String dateFormat="ss mm HH dd MM ? yyyy";
return formatDateByPattern(date, dateFormat);
* 两个日期相差多少秒
* @param date1 : 建议大于 date2
* @param date2
public static int getTimeDelta(Date date1, Date date2) {
long timeDelta = (date1.getTime() - date2.getTime()) / 1000;//单位是秒
int secondsDelta = timeDelta & 0 ? (int) timeDelta : (int) Math.abs(timeDelta);
return secondsD
* 两个日期相差多少秒
* @param date1
* @param date2
public static int getSecondDelta(Date date1,Date date2){
long timeDelta=(date1.getTime()-date2.getTime())/1000;//单位是秒
int secondsDelta=timeDelta&0?(int)timeDelta:(int)Math.abs(timeDelta);
return secondsD
* 两个日期相差多少秒
* @param dateStr1
:yyyy-MM-dd HH:mm:ss
* @param dateStr2 :yyyy-MM-dd HH:mm:ss
public static int getSecondDelta(String dateStr1,String dateStr2){
Date date1=parseDateByPattern(dateStr1, yyyyMMddHHmmss);
Date date2=parseDateByPattern(dateStr2, yyyyMMddHHmmss);
return getSecondDelta(date1, date2);
* 两个日期相差多少秒
* @param dateStr1
* @param date2
public static int getSecondDelta(String dateStr1,Date date2){
Date date1=parseDateByPattern(dateStr1, yyyyMMddHHmmss);
return getSecondDelta(date1, date2);
* convert "T19:00:00" to " 19:00:00"
* @param input
public static String formatJsonDate(String input){
String result=input.replaceAll("([\\d]{4}-[\\d]{1,2}-[\\d]{1,2})[ \tTt]([\\d]{1,2}:[\\d]{1,2}:[\\d]{1,2})", "$1 $2");
* 转换日期,把秒转换为日期
* @param second : 秒
public static String formatSecondTime(Long second){
if(second==null||second==0){
return SystemHWUtil.EMPTY;
Date date=new Date(second*1000);
return TimeHWUtil.formatDate(date, TimeHWUtil.YYYYMMDDHHMM);
* 格式化日期,把秒数转为日期
* @param list
* @param columnName
* @param transientColumn : 已格式化的日期
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalArgumentException
* @throws IllegalAccessException
public static void formatTime(List list,String columnName,String transientColumn) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
int size=list.size();
for(int i=0;i&i++){
Object obj=list.get(i);
Object val=ReflectHWUtils.getObjectValue(obj, columnName);
if(val==null){
Long timeValue=(Long)
ReflectHWUtils.setObjectValue(obj, transientColumn,TimeHWUtil.formatSecondTime(timeValue));
* 返回人性化可读的时长
* @param time : 秒
public static TimeLong getTimeLong(long time){
TimeLong timeLong=new TimeLong();
long secondRemaining=time%86400;
int days=(int) (time/86400);
int hour=(int) (secondRemaining/(60*60));
secondRemaining=secondRemaining%(60*60);
int minutes=(int) (secondRemaining/60);
int second=(int) (secondRemaining%60);
System.out.println("day:"+days);
System.out.println("hour:"+hour);
System.out.println("minutes:"+minutes);
System.out.println("second:"+second);
timeLong.setDay(days);
timeLong.setHour(hour);
timeLong.setMinute(minutes);
timeLong.setSecond(second);
return timeL
* @param date1
* @param date2
* @return : TimeLong
public static TimeLong getDeltaDate(Date date1, Date date2) {
int second = getTimeDelta(date1, date2);
TimeLong timeLong = getTimeLong(second);
return timeL
* 从当前时间算,离 endTime还剩下多少时间
* @param endTime
* @return : 天
public static int getDeltaDate(Date endTime) {
Date date2 = getCurrentTimestamp();
return getDeltaDate(endTime, date2).getDay();
public void test_002(){
String now="";
String endTime="";
if(now.compareTo(endTime)==1){//大于
System.out.println("过期");
System.out.println("还没有过期");
ReflectHWUtils、SystemHWUtil、ValueWidget这个三个类见附件 io.1-SNAPSHOT-sources.jar
路径分别是:com.common.util.ReflectHWUtils
com.common.util.SystemHWUtil
com.string.widget.util.ValueWidget
上传了新的jar包: (454.3 KB)
(454.3 KB)
下载次数: 83
浏览 20212
jar是个空的上传了新的jar包:io.1-SNAPSHOT-sources.jar (454.3 KB)
能否提供一下ReflectHWUtils、SystemHWUtil、ValueWidget这个三个类 ReflectHWUtils、SystemHWUtil、ValueWidget这个三个类见附件 io.1-SNAPSHOT-sources.jar路径分别是:com.common.util.ReflectHWUtilscom.common.util.SystemHWUtilcom.string.widget.util.ValueWidget
TimeLong 这个类能否提供一下 感谢TimeLong的源码:package com.common.
* @author huangweii
public class TimeLong {
public int getDay() {
public void setDay(int day) {
this.day =
public int getHour() {
public void setHour(int hour) {
this.hour =
public int getMinute() {
public void setMinute(int minute) {
this.minute =
public int getSecond() {
public void setSecond(int second) {
this.second =
public String toString() {
return "day:" + day + ", hour:" + hour + ", minute:" + minute
+ ", second:" +
大神,你能不能共享下TimeHWUtil 这个工具类的源码TimeHWUtil 代码如下:package com.time.
import com.common.bean.TimeL
import com.common.util.ReflectHWU
import com.common.util.SystemHWU
import com.string.widget.util.ValueW
import java.sql.T
import java.text.ParseE
import java.text.SimpleDateF
import java.util.C
import java.util.D
import java.util.L
import java.util.L
import java.util.regex.P
* http://hw.iteye.com/blog/2225264
* @author huangweii
public class TimeHWUtil {
* yyyy-MM-dd HH:mm:ss
public static final String yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
public static final String YYYYMMDDHHMM = "yyyy-MM-dd HH:mm";
public static final String YYYYMMDDHHMM_ZH = "yyyy年MM月dd HH点mm分";
public static final String YYYYMMDDHHMMSS_ZH="yyyy年MM月dd日 HH点mm分ss秒";
public static final String yyyyMMdd = "yyyy-MM-dd";
* 没有中划线
public static final String YYYYMMDD_NO_LINE = "yyyyMMdd";
public static final String YYYYMMDD_WITH_DOT = "yyyy.MM.dd";
private TimeHWUtil() {
throw new Error("Don't let anyone instantiate this class.");
* yyyy-MM-dd HH:mm:ss
* @param timestamp
public static String formatDateTime(Timestamp timestamp) {// format date
// ,such as
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
* @param Millisecond :毫秒数
public static String formatDateTime(long Millisecond) {
Timestamp timestamp=new Timestamp(Millisecond);
return formatDateTime(timestamp);
* yyyy-MM-dd HH:mm:ss
* @param date
public static String formatDateTime(Date date) {// format date ,such as
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);
String formatStr =
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
if (date != null) {
formatStr = sdf.format(date);
return formatS
* 格式化当前时间,格式为:yyyy-MM-dd HH:mm:ss
public static String formatDateTime() {
return formatDateTime(null);
* yyyy-MM-dd
* @param timestamp
public static String formatDate(Timestamp timestamp) {// format date ,such
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
* yyyy-MM-dd
* @param date
public static String formatDate(Date date) {// format date ,such as
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String formatDateZh(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String formatDateZh(Timestamp timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
* @param formatStr
format : yyyy-MM-dd HH:mm:ss
* @throws ParseException
public static Timestamp getTimestamp4Str(String formatStr)
throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);
return new Timestamp(sdf.parse(formatStr).getTime());
* @param date
format : yyyy-MM-dd HH:mm:ss
public static Timestamp getTimestamp4Date(Date date) {
if (date == null) {
date = new Date();
return new Timestamp(date.getTime());
public static Date getDate4Str(String formatStr) throws ParseException {
String format=
if(formatStr.length()&10){
format=yyyyMMddHH
format=yyyyMM
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.parse(formatStr);
public static Date getUSDate4Str(String dateStr){
SimpleDateFormat sdf = new SimpleDateFormat("MMM d HH:mm:ss", Locale.US);
Date date= sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
* format : yyyy年MM月dd日 HH点mm分ss秒
* @param timestamp
public static String formatTimestampZH(Timestamp timestamp) {
if(ValueWidget.isNullOrEmpty(timestamp)){
/* 如果没有传参数timestamp,则默认为当前时间*/
timestamp=new Timestamp(new Date().getTime());
SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDDHHMMSS_ZH);
return sdf.format(timestamp);
public static String formatDateTimeZH(Date date) {
if(ValueWidget.isNullOrEmpty(date)){
/*若没有传递参数,则默认为当前时间*/
date=new Date();
SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDDHHMMSS_ZH);
return sdf.format(date);
* 比较是否过期 true:过期,不能正常使用 &br&false:正常使用
* @param timestamp
public static boolean compareToTimestamp(Timestamp timestamp) {
return timestamp.before(new java.util.Date());
* 比较是否过期 true:过期,不能正常使用 &br&false:正常使用
* @param date
: java.util.Date
public static boolean compareToDate(Date date) {
return date.before(new java.util.Date());
public static Timestamp getTimestampAfter(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
return new Timestamp(now.getTimeInMillis());
// public static java.util.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();
public static Timestamp getTimestampBefore(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
return new Timestamp(now.getTimeInMillis());
* @param d
:Base Date
* @param minutes
:Minutes delayed
public static java.util.Date getDateAfterMinute(Date d, int minutes) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) + minutes);
return now.getTime();
* @param d : 基准日期
* @param day : 几天前
* @throws ParseException
public static java.util.Date getDateBefore(String d, int day) throws ParseException {
java.util.Date date=getDate4Str(d);
return getDateBefore(date, day);
* @param d : 基准时间
* @param day : 几天前
public static java.util.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 second : 秒
public static java.util.Date getDateBySecond(long second){
Date date=new Date(second*1000);
* 返回秒(不是毫秒)
* @param d
* @param day
public static long getSecondBefore(Date d, int day) {
return getDateBefore(d, day).getTime()/1000;
* @param d : 基准时间
* @param day
* @throws ParseException
public static long getSecondBefore(String d, int day) throws ParseException {
java.util.Date date=getDate4Str(d);
return getDateBefore(date, day).getTime()/1000;
public static java.util.Date getDateBeforeMinute(Date d, int minutes) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) - minutes);
return now.getTime();
* @param d
* @param hour : 小时
public static java.util.Date getDateBeforeHour(Date d, int hour) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.HOUR, now.get(Calendar.HOUR) - hour);
return now.getTime();
* get current datetime
public static Timestamp getCurrentTimestamp() {
return new Timestamp(System.currentTimeMillis());
* 获取当前时间,并且格式化为"yyyy-MM-dd HH:mm:ss"
public static String getCurrentFormattedTime(){
return formatDateTime(new Date());
* @return : 当前时间的毫秒数
public static long getCurrentTimeLong(){
return new Date().getTime();
* @return : 当前时间的秒数
public static long getCurrentTimeSecond(Date date){
if(ValueWidget.isNullOrEmpty(date)){
date=new Date();
return date.getTime()/1000;
* 当前时间的秒数
public static long getCurrentTimeSecond(){
return getCurrentTimeSecond(null);
* Get current sql data
public static java.sql.Date getCurrentSQLDate(){
return new java.sql.Date(System.currentTimeMillis());
public static Calendar getCalendar() {
Calendar c = Calendar.getInstance();
public static Calendar getCalendar(Date date) {
Calendar c = Calendar.getInstance();
if(ValueWidget.isNullOrEmpty(date)){
date=new Date();
c.setTime(date);
* _yy_MM_dd_HH_mm_ss_
* @param date
public static String formatTimestamp2(Date date) {// format date ,such as
SimpleDateFormat sdf = new SimpleDateFormat("_yy_MM_dd_HH_mm_ss_");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* @param d
:Base Date
* @param day
:Delayed days
public static java.util.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();
public static java.util.Date getDateAfterByYear(Date d, int year) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.YEAR, now.get(Calendar.YEAR) + year);
return now.getTime();
* 以月为单位
* @param d
* @param month
public static java.util.Date getDateAfterByMonth(Date d, int month) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.MONTH, now.get(Calendar.MONTH) + month);
return now.getTime();
* 以小时为单位
* @param d
* @param hour
public static java.util.Date getDateAfterByHour(Date d, int hour) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.HOUR, now.get(Calendar.HOUR) + hour);
return now.getTime();
public static java.util.Date getDateAfterByHour(String dateStr, int hour) throws ParseException {
Date d = getDate4Str(dateStr);
return getDateAfterByHour(d, hour);
* Determine whether date is valid, including the case of a leap year
* @param date
YYYY-mm-dd
public static boolean isDate(String date) {
StringBuffer reg = new StringBuffer(
"^((\\d{2}(([0])|([13579][26]))-?((((0?");
reg.append("[13578])|(1[02]))-?((0?[1-9])|([1-2][0-9])|(3[01])))");
reg.append("|(((0?[469])|(11))-?((0?[1-9])|([1-2][0-9])|(30)))|");
reg.append("(0?2-?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][12");
reg.append("35679])|([189]))-?((((0?[13578])|(1[02]))");
reg.append("-?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))");
reg.append("-?((0?[1-9])|([1-2][0-9])|(30)))|(0?2-?((0?[");
reg.append("1-9])|(1[0-9])|(2[0-8]))))))");
Pattern p = Pattern.compile(reg.toString());
return p.matcher(date).matches();
* @param dateStr
public static boolean isShortDate(String dateStr) {
boolean isRegexRight = dateStr.matches("[\\d]{8}");
if (!isRegexRight) {
Date date = parseDateByPattern(dateStr, YYYYMMDD_NO_LINE);
if (date == null) {
* format Date
* @param date
* @param formatString
public static String formatDate(Date date, String formatString) {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.format(date);
} catch (Exception ex) {
return "";
public static String formatTimestamp_noSecond(Timestamp timestamp) {// format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String formatTimeStr =
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
public static String formatTimestampShortStr(Timestamp timestamp) {// format
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
public static String formatDateShortZh(Timestamp timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if (timestamp != null) {
formatTimeStr = sdf.format(timestamp);
return formatTimeS
public static String formatDateShortZh(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* "yyyy-MM-dd"
* @param date
public static String formatDateShortEN(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd);
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String formatDateZhAll(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* 获取当前的时间
* @return : 格式化之后的字符串,例如" 11:07:35"
public static String getCurrentDateTime(){
return formatDateTime(new Date());
public static String getMiniuteSecond(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
String formatTimeStr =
if(ValueWidget.isNullOrEmpty(date)){
date=new Date();
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String getMiniuteSecondZH(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("mm分ss秒");
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
public static String getCurrentMiniuteSecond() {
Date date=new Date();
return getMiniuteSecond(date);
public static String getCurrentMiniuteSecondZH() {
Date date=new Date();
return getMiniuteSecondZH(date);
* @param date
* @param dateFormat : e.g:yyyy-MM-dd HH:mm:ss
public static String formatDateByPattern(Date date,String dateFormat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
String formatTimeStr =
if (date != null) {
formatTimeStr = sdf.format(date);
return formatTimeS
* @param dateStr
* @param dateFormat
public static Date parseDateByPattern(String dateStr,String dateFormat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
* convert Date to cron ,eg.
"0 06 10 15 1 ? 2014"
* @param date
public static String getCron(java.util.Date
String dateFormat="ss mm HH dd MM ? yyyy";
return formatDateByPattern(date, dateFormat);
* 两个日期相差多少秒
* @param date1 : 建议大于 date2
* @param date2
public static int getTimeDelta(Date date1, Date date2) {
long timeDelta = (date1.getTime() - date2.getTime()) / 1000;//单位是秒
int secondsDelta = timeDelta & 0 ? (int) timeDelta : (int) Math.abs(timeDelta);
return secondsD
* 两个日期相差多少秒
* @param date1
* @param date2
public static int getSecondDelta(Date date1,Date date2){
long timeDelta=(date1.getTime()-date2.getTime())/1000;//单位是秒
int secondsDelta=timeDelta&0?(int)timeDelta:(int)Math.abs(timeDelta);
return secondsD
* 两个日期相差多少秒
* @param dateStr1
:yyyy-MM-dd HH:mm:ss
* @param dateStr2 :yyyy-MM-dd HH:mm:ss
public static int getSecondDelta(String dateStr1,String dateStr2){
Date date1=parseDateByPattern(dateStr1, yyyyMMddHHmmss);
Date date2=parseDateByPattern(dateStr2, yyyyMMddHHmmss);
return getSecondDelta(date1, date2);
* 两个日期相差多少秒
* @param dateStr1
* @param date2
public static int getSecondDelta(String dateStr1,Date date2){
Date date1=parseDateByPattern(dateStr1, yyyyMMddHHmmss);
return getSecondDelta(date1, date2);
* convert "T19:00:00" to " 19:00:00"
* @param input
public static String formatJsonDate(String input){
String result=input.replaceAll("([\\d]{4}-[\\d]{1,2}-[\\d]{1,2})[ \tTt]([\\d]{1,2}:[\\d]{1,2}:[\\d]{1,2})", "$1 $2");
* 转换日期,把秒转换为日期
* @param second : 秒
public static String formatSecondTime(Long second){
if(second==null||second==0){
return SystemHWUtil.EMPTY;
Date date=new Date(second*1000);
return TimeHWUtil.formatDate(date, TimeHWUtil.YYYYMMDDHHMM);
* 格式化日期,把秒数转为日期
* @param list
* @param columnName
* @param transientColumn : 已格式化的日期
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalArgumentException
* @throws IllegalAccessException
public static void formatTime(List list,String columnName,String transientColumn) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
int size=list.size();
for(int i=0;i&i++){
Object obj=list.get(i);
Object val=ReflectHWUtils.getObjectValue(obj, columnName);
if(val==null){
Long timeValue=(Long)
ReflectHWUtils.setObjectValue(obj, transientColumn,TimeHWUtil.formatSecondTime(timeValue));
* 返回人性化可读的时长
* @param time : 秒
public static TimeLong getTimeLong(long time){
TimeLong timeLong=new TimeLong();
long secondRemaining=time%86400;
int days=(int) (time/86400);
int hour=(int) (secondRemaining/(60*60));
secondRemaining=secondRemaining%(60*60);
int minutes=(int) (secondRemaining/60);
int second=(int) (secondRemaining%60);
System.out.println("day:"+days);
System.out.println("hour:"+hour);
System.out.println("minutes:"+minutes);
System.out.println("second:"+second);
timeLong.setDay(days);
timeLong.setHour(hour);
timeLong.setMinute(minutes);
timeLong.setSecond(second);
return timeL
* @param date1
* @param date2
* @return : TimeLong
public static TimeLong getDeltaDate(Date date1, Date date2) {
int second = getTimeDelta(date1, date2);
TimeLong timeLong = getTimeLong(second);
return timeL
* 从当前时间算,离 endTime还剩下多少时间
* @param endTime
* @return : 天
public static int getDeltaDate(Date endTime) {
Date date2 = getCurrentTimestamp();
return getDeltaDate(endTime, date2).getDay();
public void test_002(){
String now="";
String endTime="";
if(now.compareTo(endTime)==1){//大于
System.out.println("过期");
System.out.println("还没有过期");
怎样把时间段转化为corn表达式呢,quartz菜鸟,求大神指导!!!!!/***
* convert Date to cron ,eg.
"0 06 10 15 1 ? 2014"
* @param date
public static String getCron(java.util.Date
String dateFormat="ss mm HH dd MM ? yyyy";
return formatDateByPattern(date, dateFormat);
浏览: 3489254 次
来自: 北京
这个方法对于子类来说是没效果的
没这么麻烦吧,网上找了一个Holer工具,只需要配置一个Acc ...
Jmeter性能测试从入门到精通(2018年最新)课程观看地址 ...
6ee55ec8ed9fff ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 cron表达式每隔1分钟 的文章

 

随机推荐