package com.zhf.common.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.GregorianCalendar;
import static org.apache.commons.lang3.time.DateUtils.isSameDay;
public class DateUtil {
private DateUtil(){
}
private static String getDateFormat(Date date, String dateFormatType) {
SimpleDateFormat simformat = new SimpleDateFormat(dateFormatType);
return simformat.format(date);
}
public static String formatCSTTime(String date, String format) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
Date d = sdf.parse(date);
return DateUtil.getDateFormat(d, format);
}
public final static long ONE_DAY_SECONDS = 86400;
/*
* private static DateFormat dateFormat = null; private static DateFormat
* longDateFormat = null; private static DateFormat dateWebFormat = null;
*/
public final static String shortFormat = "yyyyMMdd";
public final static String longFormat = "yyyyMMddHHmmss";
public final static String webFormat = "yyyy-MM-dd";
public final static String timeFormat = "HHmmss";
public final static String monthFormat = "yyyyMM";
public final static String chineseDtFormat = "yyyy年MM月dd日";
public final static String newFormat = "yyyy-MM-dd HH:mm:ss";
public final static String newFormat2 = "yyyy-MM-dd HH:mm";
public final static String newFormat3 = "yyyy-MM-dd HH";
public final static String FULL_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
static {
/*
* dateFormat = new SimpleDateFormat(shortFormat);
* dateFormat.setLenient(false); longDateFormat = new
* SimpleDateFormat(longFormat); longDateFormat.setLenient(false);
* dateWebFormat = new SimpleDateFormat(webFormat);
* dateWebFormat.setLenient(false);
*/
}
public static long ONE_DAY_MILL_SECONDS = 86400000;
public static Date getNowDate() {
return new Date();
}
public static Date getDate(long millsecord) {
return new Date(millsecord);
}
public static DateFormat getNewDateFormat(String pattern) {
DateFormat df = new SimpleDateFormat(pattern);
df.setLenient(false);
return df;
}
public static void main(String[] args) {
Date n = new Date();
Date mm = formatDate(n, "yyyy-MM-dd");
System.out.println(mm.toString());
}
//日期格式转换,返回日期类型
public static Date formatDate(Date date, String format) {
SimpleDateFormat formatter = new SimpleDateFormat(format);
String dateString = formatter.format(date);
ParsePosition pos = new ParsePosition(0);
Date newDate = formatter.parse(dateString, pos);
return newDate;
}
//日期格式转换,返回String
public static String format(Date date, String format) {
if (date == null) {
return null;
}
return new SimpleDateFormat(format).format(date);
}
public static String formatByLong(long date, String format) {
return new SimpleDateFormat(format).format(new Date(date));
}
public static String formatByString(String date, String format) {
if (StringUtils.isNotBlank(date)) {
return new SimpleDateFormat(format).format(new Date(NumberUtils
.toLong(date)));
}
return StringUtils.EMPTY;
}
public static String formatShortFormat(Date date) {
if (date == null) {
return null;
}
return new SimpleDateFormat(shortFormat).format(date);
}
public static Date parseDateNoTime(String sDate) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat(shortFormat);
if ((sDate == null) || (sDate.length() < shortFormat.length())) {
throw new ParseException("length too little", 0);
}
if (!StringUtils.isNumeric(sDate)) {
throw new ParseException("not all digit", 0);
}
return dateFormat.parse(sDate);
}
public static Date parseDateNoTime(String sDate, String format)
throws ParseException {
if (StringUtils.isBlank(format)) {
throw new ParseException("Null format. ", 0);
}
DateFormat dateFormat = new SimpleDateFormat(format);
if ((sDate == null) || (sDate.length() < format.length())) {
throw new ParseException("length too little", 0);
}
return dateFormat.parse(sDate);
}
public static Date parseDateNoTimeWithDelimit(String sDate, String delimit)
throws ParseException {
sDate = sDate.replaceAll(delimit, "");
DateFormat dateFormat = new SimpleDateFormat(shortFormat);
if ((sDate == null) || (sDate.length() != shortFormat.length())) {
throw new ParseException("length not match", 0);
}
return dateFormat.parse(sDate);
}
public static Date parseDateLongFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(longFormat);
Date d = null;
if ((sDate != null) && (sDate.length() == longFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
}
public static Date parseDateNewFormat(String sDate) {
Date d = parseDateHelp(sDate, newFormat);
if (null != d) {
return d;
}
d = parseDateHelp(sDate, newFormat2);
if (null != d) {
return d;
}
d = parseDateHelp(sDate, newFormat3);
if (null != d) {
return d;
}
d = parseDateHelp(sDate, webFormat);
if (null != d) {
return d;
}
try {
DateFormat dateFormat = new SimpleDateFormat(newFormat);
return dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
private static Date parseDateHelp(String sDate, String format) {
if ((sDate != null) && (sDate.length() == format.length())) {
try {
DateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return null;
}
/**
* 计算当前时间几小时之后的时间
*
* @param date
* @param hours
* @return
*/
public static Date addHours(Date date, long hours) {
return addMinutes(date, hours * 60);
}
/**
* 计算当前时间几分钟之后的时间
*
* @param date
* @param minutes
* @return
*/
public static Date addMinutes(Date date, long minutes) {
return addSeconds(date, minutes * 60);
}
/**
* @param date1
* @param secs
* @return
*/
public static Date addSeconds(Date date1, long secs) {
return new Date(date1.getTime() + (secs * 1000));
}
/**
* 判断输入的字符串是否为合法的小时
*
* @param hourStr
* @return true/false
*/
public static boolean isValidHour(String hourStr) {
if (!StringUtils.isEmpty(hourStr) && StringUtils.isNumeric(hourStr)) {
int hour = new Integer(hourStr).intValue();
if ((hour >= 0) && (hour <= 23)) {
return true;
}
}
return false;
}
/**
* 判断输入的字符串是否为合法的分或秒
*
* @param
* @return true/
没有合适的资源?快使用搜索试试~ 我知道了~
毕设-基于Python的股票自动交易系统的设计与实现.zip
共688个文件
jpg:169个
png:132个
java:131个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 153 浏览量
2023-10-21
22:33:51
上传
评论
收藏 14.76MB ZIP 举报
温馨提示
随着科技的不断进步,我们的生活变得越来越离不开各种各样的程序。程序已成为我们日常生活和工作中不可或缺的一部分,它们可以帮助我们更高效地完成任务,节省时间和精力。今天,我要向大家介绍一款功能强大、用途广泛的程序,它具有万金油般的能力,可以为我们的生活带来极大的便利。 首先,这款程序具有非常强大的功能。它不仅可以帮助我们完成日常的文字处理、数据分析和报表制作等任务,还支持各种格式的文件读取和编辑。同时,它还具有多种工具和插件,可以扩展其功能,满足我们不同的需求。无论是工作还是生活,这款程序都能帮助我们轻松应对各种挑战。 其次,这款程序的界面设计非常友好。它的界面简洁明了,操作简单易懂,即使是不熟悉电脑操作的人也可以轻松上手。同时,它还支持自定义快捷键和界面主题,可以让我们根据自己的习惯和喜好进行个性化设置。 此外,这款程序还具有出色的稳定性和安全性。它采用了先进的技术和算法,可以保护我们的文件和数据安全。同时,它还支持自动备份和恢复功能,即使出现意外情况,也可以帮助我们快速恢复到之前的状态。 总之,这款程序就像生活中的万金油一样,具有广泛的应用场景和多种功能。它可以为我们的生活和工作带来便利和效率,帮助我们更好地应对各种挑战。如果您还在为处理各种任务而烦恼,不妨尝试一下这款程序,或许它会成为您的得力助手。
资源推荐
资源详情
资源评论
收起资源包目录
毕设-基于Python的股票自动交易系统的设计与实现.zip (688个子文件)
app.css 236KB
common.css 97KB
common.css 97KB
material-design-iconic-font.min.css 69KB
nwd_common.css 54KB
nwd_common.css 54KB
animate.min.css 52KB
style.min.css 27KB
jquery.scrollbar.css 22KB
sweetalert2.css 19KB
_all.css 14KB
index.css 13KB
index.css 13KB
product_details.css 12KB
product_details.css 12KB
disclosureCommon.css 11KB
login.css 8KB
daterangepicker.css 7KB
bootstrap-table.css 7KB
cart.css 6KB
header.css 6KB
header.css 6KB
product_search.css 5KB
product_search.css 5KB
cart.css 5KB
login.css 4KB
login_index.css 4KB
multiple-select.css 4KB
register.css 4KB
register.css 4KB
style.css 4KB
style.css 4KB
footer.css 2KB
footer.css 2KB
purple.css 2KB
orange.css 2KB
yellow.css 2KB
green.css 2KB
grey.css 1KB
pink.css 1KB
aero.css 1KB
blue.css 1KB
red.css 1KB
minimal.css 1KB
autocomplete.css 1KB
jquery.treegrid.css 913B
base.css 700B
base.css 700B
ip2region.db 2.6MB
Dockerfile 98B
.DS_Store 6KB
Material-Design-Iconic-Font.eot 41KB
Roboto-Medium-webfont.eot 21KB
Roboto-Regular-webfont.eot 21KB
Roboto-Bold-webfont.eot 20KB
Roboto-Light-webfont.eot 20KB
throbber.gif 2KB
.gitattributes 86B
.gitignore 101B
menuIcon.html 132KB
index.html 18KB
stock.html 13KB
index.html 13KB
product_details.html 12KB
product_details.html 12KB
newbie.html 10KB
500.html 10KB
404.html 10KB
403.html 10KB
profile.html 10KB
shenzhen.html 8KB
product_search.html 8KB
newbie_guide.html 7KB
userAdd.html 7KB
product_search.html 7KB
menuAdd.html 6KB
job.html 6KB
cart.html 5KB
cart.html 5KB
dict.html 5KB
user.html 4KB
itme7.html 4KB
itme4.html 4KB
itme5.html 4KB
itme6.html 4KB
itme2.html 4KB
itme3.html 4KB
itme1.html 4KB
info_open.html 4KB
menu.html 4KB
header.html 4KB
header.html 4KB
register.html 4KB
login.html 4KB
jobAdd.html 4KB
register.html 4KB
login.html 3KB
header.html 3KB
dictAdd.html 3KB
role.html 3KB
共 688 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
天天501
- 粉丝: 596
- 资源: 4666
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功