package com.yoho.common;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.springframework.util.StringUtils;
public class DateUtil {
/**
* 获取当前时间, 并且将当前时间转换称INT类型
*
* @return 当前时间的INT类型
*/
public static int getCurrentTimeSeconds() {
long longTime = new Date().getTime();
return (int) (longTime / 1000);
}
/**
* 将通过getTime获得的long型的时间,转换成format类型的时间,如"2015-08-09"
*
* @param time
* long型的时间戳
* @param format
* 需要转化的类型 “yyyy-MM-dd”
* @return String "2015-08-09"
*/
public static String long2DateStr(long time, String format) {
Date date = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat(format);
String dateStr = sdf.format(date);
return dateStr;
}
/**
* 转换成format类型的时间,如"2015-08-09"
*
* @param date
* 日期
* @param format
* 需要转化的类型 “yyyy-MM-dd”
* @return String "2015-08-09"
*/
public static String date2String(Date date, String format) {
if (date == null) { return null; }
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
/**
* 将通过getTime获得的Date型的时间
*
* @param time
* long型的时间戳
* @return java.util.Date
*/
public static Date long2Date(long time) {
return new Date(time);
}
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_FORMAT = "yyyy-MM-dd";
public static final String TIME_FORMAT = "HH:mm:ss";
/**
* 按照格式,取得当前时间
*
* @param str
* @return
*/
public static String getToday(String str) {
return dateToString(new Date(), str);
}
/**
* 获取今天的日期时间(yyyy-MM-dd HH:mm:ss)
*
* @return
*/
public static String getcurrentDateTime() {
return getToday(DATE_TIME_FORMAT);
}
/**
* 获取今天的日期(yyyy-MM-dd)
*
* @return
*/
public static String getcurrentDate() {
return getToday(DATE_FORMAT);
}
/**
* 获取今天的日期(HH:mm:ss)
*
* @return
*/
public static String getcurrentTime() {
return getToday(TIME_FORMAT);
}
/**
* 对日期进行加减
*
* @param date
* 被转换的日期
* @param type
* 转换类型(y-年,M-月,d-日, H-小时, m-分钟, s-秒)
* @param offset
* 转换的单位
* @param simpleDateFormat
* 日期格式
* @return
*/
public static String dateAdd(String date, String type, int offset, String simpleDateFormat) {
if (StringUtils.isEmpty(date)) {
return null;
}
if (StringUtils.isEmpty(type)) {
return date;
}
if (offset == 0) {
return date;
}
Calendar cal = Calendar.getInstance();
cal.setTime(stringToDate(date, simpleDateFormat));
if (type.equals("y")) {
cal.add(Calendar.YEAR, offset);
} else if (type.equals("M")) {
cal.add(Calendar.MONTH, offset);
} else if (type.equals("d")) {
cal.add(Calendar.DATE, offset);
} else if (type.equals("H")) {
cal.add(Calendar.HOUR, offset);
} else if (type.equals("m")) {
cal.add(Calendar.MINUTE, offset);
} else if (type.equals("s")) {
cal.add(Calendar.SECOND, offset);
}
return dateToString(cal.getTime(), simpleDateFormat);
}
/**
* ͳDate型日期转换为String型
*
* @param date
* @param simpleDateFormat
* @return
*/
public static String dateToString(Date date, String simpleDateFormat) {
SimpleDateFormat format = new SimpleDateFormat(simpleDateFormat);
if (date == null) {
return null;
} else {
return format.format(date);
}
}
/**
* String型日期转换为Date型
*
* @param date
* @param simpleDateFormat
* @return
*/
public static Date stringToDate(String date, String simpleDateFormat) {
SimpleDateFormat format = new SimpleDateFormat(simpleDateFormat);
Date d = null;
if (StringUtils.isEmpty(date)) {
return null;
} else {
try {
d = format.parse(date);
} catch (ParseException e) {
}
return d;
}
}
/**
* 日期格式转换
*
* @param date
* @param from
* @param to
* @return
*/
public static String formatDate(String date, String from, String to) {
return dateToString(stringToDate(date, from), to);
}
/**
* 获取当前时间距离输入时间的毫秒数。如果输入时间小于当前时间,则取第二天的同一时间 时间格式(HH:mm:ss)
*
* @param time
* @return
*/
public static long getTimeDiff(String time) {
if (StringUtils.isEmpty(time)) {
return 0;
}
Date d1 = new Date();
Date d2 = null;
String nowDate = dateToString(d1, "yyyy-MM-dd");
String nowTime = dateToString(d1, "HH:mm:ss");
if (time.compareTo(nowTime) >= 0) {
d2 = stringToDate(nowDate + " " + time, "yyyy-MM-dd HH:mm:ss");
} else {
d2 = stringToDate(dateAdd(nowDate, "d", 1, "yyyy-MM-dd") + " " + time, "yyyy-MM-dd HH:mm:ss");
}
return d2.getTime() - d1.getTime();
}
/**
* 从start到end的毫秒数
*
* @param start
* @param end
* @param format
* @return
* @throws Exception
*/
public static long getTimeDiff(String start, String end, String format) throws Exception {
if (StringUtils.isEmpty(start) || StringUtils.isEmpty(end) || StringUtils.isEmpty(format)) {
return 0;
}
return stringToDate(end, format).getTime() - stringToDate(start, format).getTime();
}
/**
* 获取当前时间的距离 1970-01-01的秒数
*
* @return
*/
public static int getCurrentTimeSecond() {
Date date = new Date();
int second = (int) (date.getTime() / 1000);
return second;
}
/**
* 获取与当前时间间隔天数的时间点距离 1970-01-01的秒数
*
* @param interval
* 与今天的天数间隔,如昨天则传-1, 明天则传 1
* @return 距离 1970-01-01的秒数
*/
public static int getIntervalTimeSecond(int interval) {
Calendar now = Calendar.getInstance();
now.add(Calendar.DAY_OF_YEAR, interval);
return (int) (now.getTimeInMillis() / 1000);
}
/**
* 根据当前时间距离1970-01-01的秒数,获取当前时间的date类型
*
* @param second
* @return
*/
public static Date getDateBySecond(long second) {
long secondLong = second * 1000;
return new Date(secondLong);
}
/**
* 根据距离1970-01-01的秒数,获取当前时间的String类型
*
* @param second
* 秒数
* @param format
* 时间格式
* @return
*/
public static Strin
没有合适的资源?快使用搜索试试~ 我知道了~
后台查询数据,在页面用树展示
共78个文件
class:16个
js:16个
css:13个
需积分: 50 24 下载量 69 浏览量
2016-08-15
16:14:28
上传
评论 1
收藏 887KB ZIP 举报
温馨提示
直接部署项目就可执行(maven项目),如果启动时后台报找不到某个dispatchServelet时,点击Properties 选择DeploymentAssembly 再点击右边的Add按钮选择Java Build PathEntries后点击Next按钮然后选择你的MavenDependencies 确定即可。 还需要注意的是,在后台查询数据,数据库字段里必须有TreeInfo实体类中的那几个字段,而且需要注意的是,最上面的节点的parentId必须是0,其下面的字节点的parentId必须是这个节点的id。如果不是最后一个节点(下面没有子节点了)isLeaf都是0,只有最后的节点是1.如果需要改字段名称的话,在script中也要注意修改,在赋值的时候用到
资源推荐
资源详情
资源评论
收起资源包目录
Note.zip (78个子文件)
Note
.project 1KB
src
test
java
main
webapp
WEB-INF
web.xml 2KB
treeCSS
fonts
titillium
titilliumweb-regular-webfont.woff 27KB
titilliumweb-regular-webfont.ttf 50KB
throbber.gif 2KB
32px.png 3KB
style.css 33KB
images
calendar-arrow.png 3KB
js
pagination.js 3KB
jquery-1.12.0.min.js 95KB
bootstrap.combo.js 4KB
yoho.tree.js 4KB
bootstrap.combobox.js 6KB
echarts.min.js 450KB
jquery-ui-1.10.3.min.js 223KB
bootstrap.validate.js 7KB
bootstrap.textbox.js 3KB
bootstrap.panel.js 5KB
bootstrap-timepicker.min.js 14KB
jstree.js 288KB
esl.source.js 46KB
highcharts.src.js 716KB
bootstrap.min.js 31KB
jquery-2.1.4.min.js 82KB
fonts
glyphicons-halflings-regular.ttf 40KB
fontawesome-webfont.woff 82KB
glyphicons-halflings-regular.woff 23KB
fontawesome-webfont.ttf 138KB
tree.jsp 4KB
css
style.default.css 71KB
animate.delay.css 12KB
morris.css 500B
pace.css 2KB
bootstrap-override.css 17KB
toggles.css 5KB
animate.min.css 50KB
bootstrap.min.css 107KB
font-awesome.min.css 20KB
weather-icons.min.css 6KB
jquery-ui-1.10.3.css 20KB
bootstrap.css 151KB
resources
spring-mvc.xml 3KB
spring.xml 956B
java
com
yoho
common
Response.java 1KB
DateUtil.java 9KB
controller
Tree.java 2KB
target
m2e-wtp
web-resources
META-INF
MANIFEST.MF 105B
maven
com.yoho
Note
pom.properties 198B
pom.xml 3KB
classes
com
yoho
common
Response.class 1KB
DateUtil.class 5KB
controller
EntityController.class 2KB
Time.class 1KB
Tree.class 2KB
Tree$TreeInfo.class 1KB
TestThread.class 858B
TestThread$1.class 894B
EntityController$Series.class 1KB
Combox$selectInfo.class 933B
EntityController$EchartData.class 1008B
Table.class 1KB
Combox.class 3KB
Chart$Test.class 1KB
Chart.class 2KB
Table$TableValue.class 1KB
spring-mvc.xml 3KB
spring.xml 956B
test-classes
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 300B
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 430B
org.eclipse.wst.validation.prefs 50B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.prefs.xml 171B
org.eclipse.wst.common.component 737B
.jsdtscope 575B
pom.xml 3KB
.classpath 1KB
共 78 条
- 1
资源评论
中单大魔王
- 粉丝: 50
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功