1,
package com.banksteel.openerp.common.vo;
import java.io.Serializable;
public class TimeIntervalVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1568237892596588268L;
private Long beginInMillis; // 设置时间当天的零点
private Long endInMillis; // 设置时间当天最后一秒
private String beginInString; // 显示时间
private String endInString; // 显示时间
public Long getBeginInMillis() {
return beginInMillis;
}
public void setBeginInMillis(Long beginInMillis) {
this.beginInMillis = beginInMillis;
}
public Long getEndInMillis() {
return endInMillis;
}
public void setEndInMillis(Long endInMillis) {
this.endInMillis = endInMillis;
}
public String getBeginInString() {
return beginInString;
}
public void setBeginInString(String beginInString) {
this.beginInString = beginInString;
}
public String getEndInString() {
return endInString;
}
public void setEndInString(String endInString) {
this.endInString = endInString;
}
@Override
public String toString() {
return "TimeIntervalVO [beginInMillis=" + beginInMillis + ", endInMillis=" + endInMillis + ", beginInString="
+ beginInString + ", endInString=" + endInString + "]";
}
}
2.
/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
package cn.mysteel.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
public class DateUtils
{
public DateUtils()
{
}
public static Date getDate(String s)
{
return getDate(s, null);
}
public static Date getJustDate(String s)
{
return getDate(s, "yyyy-MM-dd");
}
public static Date getDate(long date)
{
return getDate(date, null);
}
public static Date getJustDate(long date)
{
return getDate(date, "yyyy-MM-dd");
}
public static Date getDate(long date, String format)
{
if(StringUtils.isEmpty(format))
format = "yyyy-MM-dd HH:mm:ss";
return getDate(formatDate(new Date(date), format), format);
}
public static Date getDate(String s, String format)
{
Date date;
try
{
if(StringUtils.isEmpty(format))
format = "yyyy-MM-dd HH:mm:ss";
date = (new SimpleDateFormat(format)).parse(s);
}
catch(Exception e)
{
date = new Date(0L);
}
return date;
}
public static String formatDate(long date, String format)
{
return formatDate(new Date(date), format);
}
public static String formatDate(long date)
{
return formatDate(new Date(date), null);
}
public static String formatJustDate(long date)
{
return formatDate(new Date(date), "yyyy-MM-dd");
}
public static String formatDate(Date date, String format)
{
if(StringUtils.isEmpty(format))
format = "yyyy-MM-dd HH:mm:ss";
return (new SimpleDateFormat(format)).format(date);
}
public static final String DATE_FROMAT1 = "yyyy-MM-dd";
public static final String DATE_FROMAT2 = "yyyy-MM-dd HH:mm:ss";
}
/*
DECOMPILATION REPORT
Decompiled from: D:\eclipse\demo-maven\repository\cn\mysteel\shgl-core\1.0.0-SNAPSHOT\shgl-core-1.0.0-SNAPSHOT.jar
Total time: 321 ms
Jad reported messages/errors:
Exit status: 0
Caught exceptions:
*/
3
package com.banksteel.openerp.utils;
import java.util.Calendar;
import com.banksteel.openerp.common.vo.TimeIntervalVO;
import cn.mysteel.util.DateUtils;
/**
* 时间工具类
*
* @description:
* @projectName:openerp-webapp
* @className:TimeUtils.java
* @createTime:2016年9月27日 下午4:02:40
* @version 1.0
*/
public class TimeUtils {
private TimeUtils() {
};
/**
* 获取基准时间戳计算指定天数后的当天00:00:00.000至23:59:59.999时间戳区间
*
* @param millis
* 基准时间戳
* @param dayOffset
* 偏移天数,0表示当天,正数表示基准时间戳之后N天,负数反之
* @createTime:2016年9月29日 下午5:19:40
*/
public static TimeIntervalVO getMillisInterval(Long millis, int dayOffset) {
TimeIntervalVO interval = new TimeIntervalVO();
Calendar calendar = Calendar.getInstance();
if (millis > 0) {
calendar.setTime(DateUtils.getDate(millis, "yyyy-MM-dd"));
calendar.add(Calendar.DATE, dayOffset);
interval.setBeginInMillis(calendar.getTimeInMillis());
interval.setBeginInString(DateUtils.formatDate(calendar.getTimeInMillis(), "yyyy-MM-dd HH:mm:ss.SSS"));
interval.setEndInMillis(calendar.getTimeInMillis() + 86400000L - 1L);
interval.setEndInString(
DateUtils.formatDate(calendar.getTimeInMillis() + 86400000L - 1L, "yyyy-MM-dd HH:mm:ss.SSS"));
}
return interval;
}
}
4,java调用
public static void main(String[] args)
{
//当前时间
Long currentTimeMillis = System.currentTimeMillis();
// 30天前时间
TimeIntervalVO beginTime = null;
beginTime = TimeUtils.getMillisInterval(currentTimeMillis, -30);
// 昨天时间
TimeIntervalVO endTime = null;
endTime = TimeUtils.getMillisInterval(currentTimeMillis, -1);
System.out.println(beginTime.toString());
System.out.println(endTime.toString());
}
显示结果