/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dwz.common.util.time;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.TimeZone;
import dwz.common.util.StringUtils;
/**
* 常用日期工具
* <p>A suite of utilities surrounding the use of the
* {@link java.util.Calendar} and {@link java.util.Date} object.</p>
*
* <p>DateUtils contains a lot of common methods considering manipulations
* of Dates or Calendars. Some methods require some extra explanation.
* The truncate, ceiling and round methods could be considered the Math.floor(),
* Math.ceil() or Math.round versions for dates
* This way date-fields will be ignored in bottom-up order.
* As a complement to these methods we've introduced some fragment-methods.
* With these methods the Date-fields will be ignored in top-down order.
* Since a date without a year is not a valid date, you have to decide in what
* kind of date-field you want your result, for instance milliseconds or days.
* </p>
*
*
*
* @author Apache Software Foundation
* @author <a href="mailto:sergek@lokitech.com">Serge Knystautas</a>
* @author Janek Bogucki
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @author Phil Steitz
* @author Robert Scholte
* @since 2.0
* @version $Id: DateUtils.java 911986 2010-02-19 21:19:05Z niallp $
*/
public class DateUtils {
/**
* The UTC time zone (often referred to as GMT).
*/
public static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("GMT");
/**
* Number of milliseconds in a standard second.
* @since 2.1
*/
public static final long MILLIS_PER_SECOND = 1000;
/**
* Number of milliseconds in a standard minute.
* @since 2.1
*/
public static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND;
/**
* Number of milliseconds in a standard hour.
* @since 2.1
*/
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
/**
* Number of milliseconds in a standard day.
* @since 2.1
*/
public static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR;
/**
* This is half a month, so this represents whether a date is in the top
* or bottom half of the month.
*/
public final static int SEMI_MONTH = 1001;
private static final int[][] fields = {
{Calendar.MILLISECOND},
{Calendar.SECOND},
{Calendar.MINUTE},
{Calendar.HOUR_OF_DAY, Calendar.HOUR},
{Calendar.DATE, Calendar.DAY_OF_MONTH, Calendar.AM_PM
/* Calendar.DAY_OF_YEAR, Calendar.DAY_OF_WEEK, Calendar.DAY_OF_WEEK_IN_MONTH */
},
{Calendar.MONTH, DateUtils.SEMI_MONTH},
{Calendar.YEAR},
{Calendar.ERA}};
/**
* A week range, starting on Sunday.
*/
public final static int RANGE_WEEK_SUNDAY = 1;
/**
* A week range, starting on Monday.
*/
public final static int RANGE_WEEK_MONDAY = 2;
/**
* A week range, starting on the day focused.
*/
public final static int RANGE_WEEK_RELATIVE = 3;
/**
* A week range, centered around the day focused.
*/
public final static int RANGE_WEEK_CENTER = 4;
/**
* A month range, the week starting on Sunday.
*/
public final static int RANGE_MONTH_SUNDAY = 5;
/**
* A month range, the week starting on Monday.
*/
public final static int RANGE_MONTH_MONDAY = 6;
/**
* Constant marker for truncating
*/
private final static int MODIFY_TRUNCATE = 0;
/**
* Constant marker for rounding
*/
private final static int MODIFY_ROUND = 1;
/**
* Constant marker for ceiling
*/
private final static int MODIFY_CEILING= 2;
/**
* <p><code>DateUtils</code> instances should NOT be constructed in
* standard programming. Instead, the class should be used as
* <code>DateUtils.parse(str);</code>.</p>
*
* <p>This constructor is public to permit tools that require a JavaBean
* instance to operate.</p>
*/
public DateUtils() {
super();
}
//-----------------------------------------------------------------------
/**
* <p>Checks if two date objects are on the same day ignoring time.</p>
*
* <p>28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.
* 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
* </p>
*
* @param date1 the first date, not altered, not null
* @param date2 the second date, not altered, not null
* @return true if they represent the same day
* @throws IllegalArgumentException if either date is <code>null</code>
* @since 2.1
*/
public static boolean isSameDay(Date date1, Date date2) {
if (date1 == null || date2 == null) {
throw new IllegalArgumentException("The date must not be null");
}
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
return isSameDay(cal1, cal2);
}
/**
* <p>Checks if two calendar objects are on the same day ignoring time.</p>
*
* <p>28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.
* 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
* </p>
*
* @param cal1 the first calendar, not altered, not null
* @param cal2 the second calendar, not altered, not null
* @return true if they represent the same day
* @throws IllegalArgumentException if either calendar is <code>null</code>
* @since 2.1
*/
public static boolean isSameDay(Calendar cal1, Calendar cal2) {
if (cal1 == null || cal2 == null) {
throw new IllegalArgumentException("The date must not be null");
}
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
//-----------------------------------------------------------------------
/**
* <p>Checks if two date objects represent the same instant in time.</p>
*
* <p>This method compares the long millisecond time of the two objects.</p>
*
* @param date1 the first date, not altered, not null
* @param date2 the second date, not altered, not null
* @return true if they represent the same millisecond instant
* @throws IllegalArgumentException if either date is <code>null</code>
* @since 2.1
*/
public static boolean isSameInstant(Date date1, Date date2) {
if (date1 == null || date2 == null) {
throw new IllegalArgumentException("The date must not be null");
}
return date1.getTime() == date2.getTime();
}
/**
* <p>Checks if two calendar objects represent the same instant in time.</p>
*
* <p>This method compares the long millisecond time of
没有合适的资源?快使用搜索试试~ 我知道了~
dwz_spring.rar_dwz
共228个文件
java:210个
xml:12个
properties:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 172 浏览量
2022-09-24
20:40:45
上传
评论
收藏 231KB RAR 举报
温馨提示
dwz spring mvc 例子,包含整个工程样例,详细下载查看
资源推荐
资源详情
资源评论
收起资源包目录
dwz_spring.rar_dwz (228个子文件)
DateUtils.java 75KB
StringUtils.java 62KB
MemcachedClient.java 58KB
FastDateFormat.java 56KB
SockIOPool.java 52KB
DurationFormatUtils.java 25KB
CacheManager.java 19KB
MemcacheCacheManager.java 17KB
NativeHandler.java 13KB
DateFormatUtils.java 12KB
AppConfiguration.java 11KB
StopWatch.java 10KB
ReflectionUtils.java 9KB
PropertiesHelper.java 9KB
RandomGUID.java 8KB
DateUtil.java 6KB
ReflectUtil.java 6KB
Queue.java 5KB
ThreadPool.java 5KB
AbstractBusinessObjectServiceMgr.java 5KB
WebUtils.java 5KB
OffsetLimitInterceptor.java 5KB
FileUtils.java 5KB
UserServiceMgrImpl.java 4KB
SessionValidateFilter.java 4KB
TaskEngine.java 4KB
CollectionHelper.java 4KB
BaseController.java 4KB
ImageUtil.java 4KB
Logger.java 4KB
SysUser.java 4KB
MapAndObject.java 3KB
SequenceGenerator.java 3KB
MailImpl.java 3KB
WebWebsite.java 3KB
TaskUnitImpl.java 3KB
NewsServiceMgrImpl.java 3KB
PassportController.java 3KB
TaskParseImpl.java 3KB
PageInfo.java 3KB
WebsiteServiceMgrImpl.java 3KB
ByteBufArrayInputStream.java 3KB
FreeMarkerUtil.java 3KB
Template.java 3KB
WebPage.java 3KB
User.java 3KB
PagedQuery.java 3KB
Page.java 3KB
EncodeUtils.java 3KB
ErrorHandler.java 3KB
SQLServer2005Dialect.java 3KB
PinyinUtil.java 3KB
Validator.java 3KB
StringEncryptUtil.java 3KB
NewsController.java 3KB
InfNews.java 3KB
News.java 2KB
WebsiteContextFilter.java 2KB
MemcachedClientSocketPoolConfig.java 2KB
Website.java 2KB
ClassFactoryUtil.java 2KB
PowerUtil.java 2KB
UserController.java 2KB
LoopRunnable.java 2KB
SysResource.java 2KB
ThreadUtils.java 2KB
MailManagerImpl.java 2KB
PagerInfoTag.java 2KB
SysRole.java 2KB
WebpageController.java 2KB
ExecUtils.java 2KB
PageUtil.java 2KB
IpRangeUtils.java 2KB
MD5Util.java 2KB
DefaultMessageConverter.java 2KB
FileSizeUtils.java 2KB
ScanClassUtils.java 2KB
Resource.java 2KB
BaseConditionVO.java 2KB
Constants.java 2KB
DB2Dialect.java 2KB
AbstractBusinessObject.java 2KB
DefaultErrorHandlerImpl.java 2KB
CommonUtils.java 2KB
PropertiesUtils.java 2KB
ObjectUtils.java 2KB
PagerPagesTag.java 2KB
SqlRemoveUtils.java 2KB
ResponseHeaderFilter.java 2KB
DateConvertUtils.java 2KB
PagerNextpagesTag.java 2KB
ServiceRuntimeException.java 2KB
WebsiteController.java 2KB
MemcachedClientConfig.java 2KB
Role.java 2KB
FileStoreUtils.java 2KB
SpringContextHolder.java 2KB
ServiceException.java 2KB
PagerWriteTag.java 2KB
InfoEL.java 2KB
共 228 条
- 1
- 2
- 3
资源评论
weixin_42653672
- 粉丝: 93
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功