package com.javapandeng.utils;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* 日期格式化类
*/
public class DateUtil extends java.util.Date {
private static final long serialVersionUID = 1L;
private static final DateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static final String strFormat1 = "yyyy-MM-dd HH:mm";
/**
M 年中的月份 Month July; Jul; 07
w 年中的周数 Number 27
W 月份中的周数 Number 2
D 年中的天数 Number 189
d 月份中的天数 Number 10
F 月份中的星期 Number 2
E 星期中的天数 Text Tuesday; Tue
a Am/pm 标记 Text PM
H 一天中的小时数(0-23) Number 0
k 一天中的小时数(1-24) Number 24
K am/pm 中的小时数(0-11) Number 0
h am/pm 中的小时数(1-12) Number 12
m 小时中的分钟数 Number 30
s 分钟中的秒数 Number 55
S 毫秒数 Number 978
z 时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z 时区 RFC 822 time zone -0800
*/
/**
* 构造函数
*/
public DateUtil() {
super(getSystemDate().getTime().getTime());
}
/**
* 当前时间
*
* @return 时间Timestamp
*/
public java.sql.Timestamp parseTime() {
return new java.sql.Timestamp(this.getTime());
}
/**
* 将Date类型转换为字符串 yyyy-MM-dd HH:mm:ss
*
* @param Date
* @return String
*/
public static String format(Date date) {
return format(date, null);
}
/**
* 将Date类型转换为字符串
*
* @param Date
* @param pattern 字符串格式
* @return String
*/
public static String format(Date date, String pattern) {
if (date == null) {
return "";
} else if (pattern == null || pattern.equals("") || pattern.equals("null")) {
return datetimeFormat.format(date);
} else {
return new SimpleDateFormat(pattern).format(date);
}
}
/**
* 将Date类型转换为字符串 yyyy-MM-dd
*
* @param Date
* @return String
*/
public static String formatDate(Date date) {
if (date == null) {
return "";
}
return dateFormat.format(date);
}
/**
* 将字符串转换为Date类型
*
* @param sDate yyyy-MM-dd HH:mm:ss
* @return
*/
public static Date convert(String sDate) {
try {
if (sDate != null) {
if (sDate.length() == 10) {
return dateFormat.parse(sDate);
} else if (sDate.length() == 19) {
return datetimeFormat.parse(sDate);
}
}
} catch (ParseException pe) {
}
return convert(sDate, null);
}
/**
* 将字符串转换为Date类型
*
* @param sDate
* @param pattern 格式
* @return
*/
public static Date convert(String sDate, String pattern) {
Date date = null;
try {
if (sDate == null || sDate.equals("") || sDate.equals("null")) {
return null;
} else if (pattern == null || pattern.equals("") || pattern.equals("null")) {
return datetimeFormat.parse(sDate);
} else {
return new SimpleDateFormat(pattern).parse(sDate);
}
} catch (ParseException pe) {
}
return date;
}
/**
* String转换为Date
*
* @param sDate 日期"yyyy-MM-dd"
* @return 日期Date
*/
public static Date convertDate(String dateStr) {
return convert(dateStr, "yyyy-MM-dd");
}
/**
* String转换为Timestamp
*
* @param sDate 日期 "yyyy-MM-dd" / "yyyy-MM-dd HH:mm:ss"
* @return 日期Timestamp
*/
public static Timestamp convertTimestamp(String sDate) {
if (sDate.length() == 10) {
sDate = sDate + " 00:00:00";
}
if (sDate.length() == 16) {
sDate = sDate + ":00";
}
return Timestamp.valueOf(sDate);
}
/**
* Date转换为Timestamp
*/
public static Timestamp convert(Date date) {
return new Timestamp(date.getTime());
}
/**
* 取当前日期(yyyy-mm-dd)
*
* @return 时间Timestamp
*/
public static String getTodayDate() {
return formatDate(new Date());
}
/**
* 取当前日期(yyyy-mm-dd hh:mm:ss)
*
* @return 时间Timestamp
*/
public static String getTodayDateTime() {
return format(new Date());
}
/**
* 取得n分钟后的时间
*
* @param date 日期
* @param afterMins
* @return 时间Timestamp
*/
public static Date getAfterMinute(Date date, long afterMins) {
if (date == null)
date = new Date();
long longTime = date.getTime() + afterMins * 60 * 1000;
return new Date(longTime);
}
/**
* add by yinshengming start 2016-4-7
* 取得n秒后的时间
*
* @param date 日期
* @param afterMins
* @return 时间Timestamp
*/
public static Date getAfterSecond(Date date, long afterMins) {
if (date == null)
date = new Date();
long longTime = date.getTime() + afterMins * 1000;
return new Date(longTime);
}
// public static void main(String[] arg) {
// System.err.println(format((new Date())));
// System.err.println(format(getAfterMinute(new Date(), 3)));
// }
/**
* 取得指定日期几天后的日期
*
* @param date 日期
* @param afterDays 天数
* @return 日期
*/
public static Date getAfterDay(Date date, int afterDays) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.DATE, afterDays);
return cal.getTime();
}
/**
* 取得指定日期几天后的日期
*
* @param sDate 日期 yyyy-MM-dd
* @param afterDays 天数
* @return 日期
*/
public static String getAfterDay(String sDate, int afterDays) {
Date date = convertDate(sDate);
date = getAfterDay(date, afterDays);
return formatDate(date);
}
/**
* 取得指定日期几天前的日期
*
* @param date 日期
* @param beforeDays 天数(大于0)
* @return 日期
*/
public static Date getBeforeDay(Date date, int beforeDays) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.DATE, 0 - Math.abs(beforeDays));
return cal.getTime();
}
/**
* 取得指定日期几天前的日期
*
* @param sDate 日期 yyyy-MM-dd
* @param beforeDays 天数(大于0)
* @return 日期
*/
public static String getBeforeDay(String sDate, int beforeDays) {
Date date = convertDate(sDate);
date = getBeforeDay(date, beforeDays);
return formatDate(date);
}
/**
* 获得几个月后的日期
*
* @param date 日期
* @param afterMonth 月数
* @return 日期Date
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一、项目简述 功能: 功能:系统分管理员界面与用户界面 管理员:用户管理,商品类别管理,商品管理,订单管理,公 告管理留言里筲等 向户:房总主册功能,用户登录功能,商品浏览,商品留言评 论,商品购买,商品支付,订单查询等等 二、项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + Fileupload + maven等等。
资源推荐
资源详情
资源评论
收起资源包目录
Java项目:蔬菜网上商城+后台管理系统(java+SSM+mysql+maven+tomcat) (2000个子文件)
0a07dba0db8211eac9b6298457e97242 0B
0a0829c0db8211eac9b6298457e97242 0B
0a0850d0db8211eac9b6298457e97242 0B
0a089ef0db8211eac9b6298457e97242 0B
0a08c600db8211eac9b6298457e97242 0B
1cc599e0db9a11ea67b685a5a413e38f 0B
1cc5e800db9a11ea67b685a5a413e38f 0B
1cc68440db9a11ea67b685a5a413e38f 0B
1dbc2ee0db9a11ea67b685a5a413e38f 0B
1dbc7d00db9a11ea67b685a5a413e38f 0B
345cc3e0e05811eae3aca2ee73973e9d 0B
34604650e05811eae3aca2ee73973e9d 0B
3460bb80e05811eae3aca2ee73973e9d 0B
346109a0e05811eae3aca2ee73973e9d 0B
349472b0db9711ea0b826466c302d111 0B
349499c0db9711ea0b826466c302d111 0B
3494c0d0db9711ea0b826466c302d111 0B
3494c0d1db9711ea0b826466c302d111 0B
349c3ae0db9711ea0b826466c302d111 0B
3d137290e05811eae3aca2ee73973e9d 0B
3d1399a0e05811eae3aca2ee73973e9d 0B
3d13c0b0e05811eae3aca2ee73973e9d 0B
3d13e7c0e05811eae3aca2ee73973e9d 0B
4291c4b0db9911ea7b7187765c626cd6 0B
429212d0db9911ea7b7187765c626cd6 0B
4298c990db9911ea7b7187765c626cd6 0B
429917b0db9911ea7b7187765c626cd6 0B
429965d0db9911ea7b7187765c626cd6 0B
46e1e9a01dfe11e99354e3b6b20f9f59 0B
46ed0d301dfe11e99354e3b6b20f9f59 0B
46ed34401dfe11e99354e3b6b20f9f59 0B
46f523801dfe11e99354e3b6b20f9f59 0B
46f523811dfe11e99354e3b6b20f9f59 0B
46f8a5f01dfe11e99354e3b6b20f9f59 0B
5b8c7de0db9711ea0b826466c302d111 0B
5b8ca4f0db9711ea0b826466c302d111 0B
5b8cf310db9711ea0b826466c302d111 0B
5b8d1a20db9711ea0b826466c302d111 0B
5b8d6840db9711ea0b826466c302d111 0B
65a730c0db9411ea6a9dbdfc1ff92519 0B
65ae83c0db9411ea6a9dbdfc1ff92519 0B
65aed1e0db9411ea6a9dbdfc1ff92519 0B
65aef8f0db9411ea6a9dbdfc1ff92519 0B
6e0f8570de1211ea71c6225875bd23c0 0B
6e14dca0de1211ea71c6225875bd23c0 0B
6e1503b0de1211ea71c6225875bd23c0 0B
6e152ac0de1211ea71c6225875bd23c0 0B
793950a0db9911ea335b527dccdc447f 0B
79399ec0db9911ea335b527dccdc447f 0B
793a13f0db9911ea335b527dccdc447f 0B
793a3b00db9911ea335b527dccdc447f 0B
793a8920db9911ea335b527dccdc447f 0B
7d9193e0d78b11ea4d5086ad83b81a31 0B
7d91e200d78b11ea4d5086ad83b81a31 0B
7d923020d78b11ea4d5086ad83b81a31 0B
82739920db9711ea0b826466c302d111 0B
82740e50db9711ea0b826466c302d111 0B
8274d1a0db9711ea0b826466c302d111 0B
827594f0db9711ea0b826466c302d111 0B
82763130db9711ea0b826466c302d111 0B
8796abb0db9511eaffa369fc0de21cf2 0B
8796f9d0db9511eaffa369fc0de21cf2 0B
879747f0db9511eaffa369fc0de21cf2 0B
8797bd20db9511eaffa369fc0de21cf2 0B
8797e430db9511eaffa369fc0de21cf2 0B
88f7ad30db9311ea6a9dbdfc1ff92519 0B
88f7fb50db9311ea6a9dbdfc1ff92519 0B
88f84970db9311ea6a9dbdfc1ff92519 0B
88fed920db9311ea6a9dbdfc1ff92519 0B
88ff2740db9311ea6a9dbdfc1ff92519 0B
8f325e60666e11eadb534bc26f937e3d 0B
8f328570666e11eadb534bc26f937e3d 0B
8f328571666e11eadb534bc26f937e3d 0B
8f32ac80666e11eadb534bc26f937e3d 0B
8f32ac81666e11eadb534bc26f937e3d 0B
93bf22802c2111e865b6dc2da7582a7a 0B
93bf49902c2111e865b6dc2da7582a7a 0B
93bf49912c2111e865b6dc2da7582a7a 0B
93bf49922c2111e865b6dc2da7582a7a 0B
93bf70a02c2111e865b6dc2da7582a7a 0B
b0b1dda0db9811ea010f56a800e8a20e 0B
b0b252d0db9811ea010f56a800e8a20e 0B
b0b2a0f0db9811ea010f56a800e8a20e 0B
b0b31620db9811ea010f56a800e8a20e 0B
b0bade50db9811ea010f56a800e8a20e 0B
b3d622c0d85011eae3253f353e51e817 0B
b3ded550d85011eae3253f353e51e817 0B
b3df7190d85011eae3253f353e51e817 0B
b3e00dd0d85011eae3253f353e51e817 0B
style.css.bak 17KB
c6c1c5b01dfd11e99354e3b6b20f9f59 0B
c6c45dc01dfd11e99354e3b6b20f9f59 0B
c6ca2a201dfd11e99354e3b6b20f9f59 0B
c6ca78401dfd11e99354e3b6b20f9f59 0B
c6cac6601dfd11e99354e3b6b20f9f59 0B
c6cc74101dfd11e99354e3b6b20f9f59 0B
c8345940db9711eaf287908981bc15ab 0B
c834ce70db9711eaf287908981bc15ab 0B
c8351c90db9711eaf287908981bc15ab 0B
c8356ab0db9711eaf287908981bc15ab 0B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
OldWinePot
- 粉丝: 8523
- 资源: 392
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功