package com.xznu.edu.leave.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 DateUtils 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 DateUtils() {
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);
}
// 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
*/
public static Date getAfterMonth(Date date, int afterMonth) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.MONTH, afterMonth);
return cal.getTime();
}
/**
* 获得几个月后的日期
*
* @param sDate 日期
* @param afterMont
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本系统根据角色权限分为3大模块,即使用对象分别为实验室管理教师、普通教师与学生的3大模块。 管理端:通知管理模块、预约和借用记录管理模块、实验室管理模块、设备信息管理模块、用户管理模块、设备维修管理。 老师端和学生端:实验室预约、实验设备借用、个人信息管理
资源详情
资源评论
资源推荐
收起资源包目录
基于SSH的实验室设备管理系统 (481个子文件)
317c6fe09e8011e6a8bd379f2fed2ab4 690KB
BaseDaoImpl.class 18KB
EquipmentAction.class 14KB
RepairLogAction.class 9KB
DateUtils.class 8KB
LaboratoryAction.class 6KB
EquipmentLogAction.class 6KB
UserAction.class 5KB
Equipment.class 5KB
ExportUtils.class 4KB
UserDaoImpl.class 4KB
NoticeAction.class 4KB
LaboratoryLogDaoImpl.class 3KB
LoginAction.class 3KB
User.class 3KB
EquipmentLogDaoImpl.class 3KB
LaboratoryDaoImpl.class 3KB
Laboratory.class 3KB
EquipmentDaoImpl.class 3KB
BaseServiceImpl.class 3KB
RepairLogDaoImpl.class 3KB
NoticeDaoImpl.class 3KB
RepairLog.class 3KB
LaboratoryLogAction.class 3KB
LaboratoryLog.class 3KB
SystemContextFilter.class 3KB
EquipmentLog.class 3KB
UUIDUtils.class 2KB
SystemContext.class 2KB
RoleDaoImpl.class 2KB
Notice.class 2KB
UserServiceImpl.class 2KB
Pager.class 1KB
EquipmentLogServiceImpl.class 1KB
LaboratoryServiceImpl.class 1KB
EquipmentServiceImpl.class 1KB
LaboratoryLogServiceImpl.class 1KB
RepairLogServiceImpl.class 1KB
NoticeServiceImpl.class 1KB
MyStrutsFilter.class 1KB
JsonUtils.class 1KB
UserUtils.class 1KB
Role.class 1KB
RoleServiceImpl.class 1KB
BaseDao.class 866B
BaseService.class 753B
UserService.class 750B
UserDao.class 732B
LaboratoryLogService.class 622B
EquipmentLogService.class 615B
LaboratoryLogDao.class 604B
LaboratoryService.class 601B
RepairLogService.class 594B
EquipmentService.class 594B
RepairLogDao.class 576B
NoticeService.class 573B
NoticeDao.class 555B
EquipmentLogDao.class 515B
LaboratoryDao.class 503B
EquipmentDao.class 497B
RoleService.class 495B
TimeSetUtil.class 492B
RoleDao.class 477B
.classpath 767B
org.eclipse.wst.common.component 557B
org.eclipse.wst.jsdt.ui.superType.container 49B
ace.min.css 329KB
bootstrap.min.css 94KB
easyui.css 59KB
style.css 58KB
font-awesome-ie7.min.css 37KB
ace-rtl.min.css 36KB
font-awesome.css 32KB
font-awesome.min.css 27KB
ace-skins.min.css 26KB
jquery-ui-1.10.3.full.min.css 24KB
font-awesome.min.css 22KB
bootstrap-editable.css 21KB
select2.css 19KB
layer.css 14KB
chosen.css 13KB
ui.jqgrid.css 12KB
dropzone.css 11KB
fullcalendar.css 11KB
datepicker.css 10KB
echartsHome.css 8KB
codemirror.css 8KB
ace-ie.min.css 7KB
laydate.css 6KB
daterangepicker.css 5KB
colorbox.css 4KB
laydate.css 3KB
laydate.css 3KB
login.css 3KB
laydate.css 3KB
easyui_style.css 3KB
layer.ext.css 3KB
jquery-ui-1.10.3.custom.min.css 3KB
bootstrap-timepicker.css 3KB
colorpicker.css 2KB
共 481 条
- 1
- 2
- 3
- 4
- 5
曾几何时…
- 粉丝: 5754
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- SAPIEN PowerShell Studio 2024 v5.8.240 是一款功能强大且全面的集成开发环境(IDE)
- 一份关于vue开发大纲的教程!!!!!!
- Xceed Ultimate Suite 24.1.25154.0957 是一款全面的 .NET 组件和控件集合
- 在树莓派4B上,在ubuntu20.04中设置包含ros节点的文件自启动
- 一段基于汇编语言的计算斐波那契数列的代码
- 在树莓派4B上,在ubuntu20.04中设置包含ros节点的文件自启动
- 英语六级写作万能高分.docx
- 一段基于Object-C语言的计算斐波那契数列的代码
- 一段基于Rust语言的计算斐波那契数列的代码
- 没东西石达开代价大欧文见到就带大家
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1