package com.kinder.util;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class DateUtil {
/**
* 通过时间获取对应年月日
*
* @param type
* (1-年月,2-年,3-月,4-日)
* @param dt
* @return 时间字符串
* @throws ParseException
*/
public static String getDateStr(int type, String dt) throws ParseException {
if (dt == null) {
return null;
}
Date sDate;
Date eDate;
SimpleDateFormat sf;
if (dt.indexOf("-") < 0) {
sf = new SimpleDateFormat("yyyyMMdd");
} else {
sf = new SimpleDateFormat("yyyy-MM-dd");
}
sDate = sf.parse(dt);
String rs = "";
int sY = 1900 + sDate.getYear();
int sM = sDate.getMonth() + 1;
int sD = sDate.getDate();
switch (type) {
case 1:
rs += String.valueOf(sY) + (sM < 10 ? "0" + sM : String.valueOf(sM));
break;
case 2:
rs = String.valueOf(sY);
break;
case 3:
rs = sM < 10 ? "0" + sM : String.valueOf(sM);
break;
case 4:
rs = sD < 10 ? "0" + sD : String.valueOf(sD);
break;
}
return rs;
}
/**
* 对日期格式进行处理,传入Date类型的对象,输出需求的Date类型的对象
*/
public static Date dateFormat(Date inputDate, SimpleDateFormat sdf) {
Date outputDate = null;
try {
Calendar cal = Calendar.getInstance();
cal.setTime(inputDate);
String dateStr = sdf.format(cal.getTime());
outputDate = sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return outputDate;
}
public static Date get(String strDate) {
try {
SimpleDateFormat sdf;
sdf = (strDate.length() > 10) ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") : new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse(strDate);
} catch (Exception e) {
return null;
}
}
/**
* 获得时间指定格式的字符串
*
* @param inputDate
* @return
*/
public static String date2String(Date inputDate, String formatStr) {
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
return sdf.format(inputDate);
}
/**
* 获取格式为yyyy-MM-dd HH:mm:ss的串
*
* @param inputDate
* @return
*/
public static String date2String(Date inputDate) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(inputDate);
}
/**
* 获得当月日期的字符串
*
* @return
*/
public static String getFormatMonthDate() {
Date now = new Date();
SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM");
String dayStr = sdfMonth.format(now);
return dayStr;
}
/**
* 获取日期时间,格式:yyyy-MM-dd HH:mm:ss
*/
public static String getFormatFullDate(Date date) {
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (null == date) {
date = new Date();
}
return df1.format(date);
}
/**
* 当前时间+n小时
*
* @param dateHour
* 小时
* @return
*/
public static Date getDateByAddValue(int dateHour) {
long millis = 60 * 60 * 1000 * dateHour;
Date reDate = new Date(System.currentTimeMillis() + millis);
return reDate;
}
/**
* 获得当前月的第一天00时:00分00秒
*/
public static Date getDayByCurrentMonth() {
Date date = new Date();
Date firstDay = new Date(date.getYear(), date.getMonth(), 01);
return firstDay;
}
/**
* 将时间字符串转换成date
*/
public static Date getMonthBySendTimeStr(String sendTime) {
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = df1.parse(sendTime);
} catch (ParseException e) {
date = new Date();
}
return date;
}
/**
* 将时间字符串转换成date
*/
public static Date getAllBySendTimeStr(String sendTime) {
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = df1.parse(sendTime);
} catch (ParseException e) {
date = new Date();
}
return date;
}
/**
* 将时间换成字符串
*/
public static String getFullDateStr(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
/**
* 得到几天前的时间
*
* @param d
* @param day
* @return
*/
public static 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 date
* 日期(2014-04-20)
* @return 2014-03-20
* @throws ParseException
*/
public static String subMonth(String date) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dt = sdf.parse(date);
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(dt);
rightNow.add(Calendar.MONTH, -1);
Date dt1 = rightNow.getTime();
String reStr = sdf.format(dt1);
return reStr;
}
/****
* 传入具体日期 ,返回具体日期加n个月。
*
* @param date
* 日期(2014-04-20)
* @return 2014-03-20
* @throws ParseException
*/
public static Date addMonthDate(Date date, int n) {
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(date);
rightNow.add(Calendar.MONTH, n);
Date result = rightNow.getTime();
return result;
}
/****
* 传入具体日期 ,返回具体日期加n年。
*
* @param date
* 日期(2014-04-20)
* @return 2014-03-20
* @throws ParseException
*/
public static Date addYearDate(Date date, int n) {
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(date);
rightNow.add(Calendar.YEAR, n);
Date result = rightNow.getTime();
return result;
}
/****
* 传入具体日期 ,返回具体日期加n年。
*
* @param date
* 日期(2014-04-20)
* @return 2014-03-20
* @throws ParseException
*/
public static Date addDayDate(Date date, int n) {
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(date);
rightNow.add(Calendar.DAY_OF_MONTH, n);
Date result = rightNow.getTime();
return result;
}
/**
* 得到几天后的时间
*
* @param d
* @param day
* @return
*/
public static 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 Map<String, String> MonthMap = new HashMap<String, String>();
static {
MonthMap.put("Jan", "01");
MonthMap.put("Feb", "02");
MonthMap.put("Mar", "03");
MonthMap.put("Apr", "04");
MonthMap.put("May", "05");
MonthMap.put("Jun", "06");
MonthMap.put("Jul", "07");
MonthMap.put("Aug", "08");
MonthMap.put("Sept", "09");
MonthMap.put("Oct", "10");
MonthMap.put("Nov", "11");
MonthMap.put("Dec", "12");
}
/**
* 格式化时间
*
* @param date
* (11/Jan/2012:23:59:07 +0800)
* @return
*/
public static String formatDate(String date) {
if (date == null)
return null;
String dateStr = null;
String[] ds0 = date.split(" ");
String[] ds1 = ds0[0].split("/");
if (ds1.length == 3) {
String[] ds2 = ds1[2].split(":");
if (ds2.length == 4)
dateStr = ds2[0] + "-" + MonthMap.get(ds1[1]) + "-" + ds1[0] + " " + ds2[1] + ":" + ds2[2] + ":" + ds2[3];
}
return dateStr;
}
/**
* 获取两个日期相隔天数
*
* @param date1
* @param date2
* @return
*/
public static int getDays(Date date1, Date date2) {
long diff = date1.getTime(
没有合适的资源?快使用搜索试试~ 我知道了~
springboot+poi导出指定格式Excel模板

共55个文件
html:9个
class:9个
java:6个


温馨提示
springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。
资源推荐
资源详情
资源评论

















收起资源包目录






































































































共 55 条
- 1
资源评论

- 笑语轻柔2019-01-12没有请求的入口?!有点low啊
- ganggeliya2017-12-13下载下来了。代码都有,可是没运行成功。我自己用export2003/2007在自己其它项目里,没成功,数据写不进去?

Java高知社区
- 粉丝: 1374
- 资源: 90
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
