package com.atguigu.utils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
public final class DateUtils {
private DateUtils() {
super();
}
private static final Log LOG = LogFactory.getLog(DateUtils.class);
/**
* 年月日
*/
public static final String YMD = "yyyy-MM-dd";
public static final String YYYYMMDD = "yyyyMMdd";
public static final String DD = "dd";
public static final String YYYYMM = "yyyyMM";
public static final String HH = "HH";
public static final String MONTH_FORMAT = "yyyyMM";
public static final String DAY_FORMAT = "yyyyMMdd";
public static final String HOUR_FORMAT = "yyyyMMddHH";
public static final String ONLY_DAY_FORMAT = "dd";
public static final String ONLY_HOUR_FORMAT = "HH";
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_TYPE_HOUR = "hour";
public static final String DATE_TYPE_DAY = "day";
/**
* 年月日时分秒
*/
public static final String YMD_HMS = "yyyy-MM-dd HH:mm:ss";
public static final String YMD_HMSZ = "yyyy-MM-dd HH:mm:ss.SSS";
public static final String BIG = "big";
public static final String SMALL = "small";
public static final String SHORT_DATE_FORMAT_STR = "yyyy-MM-dd";
public static final String LONG_DATE_FORMAT_STR = "yyyy-MM-dd HH:mm:ss";
public static final String MAX_LONG_DATE_FORMAT_STR = "yyyy-MM-dd HH:mm:ss SSS";
public static final String HOUR_MIN_FORMAT_STR = "HH:mm";
public static final String EARLY_TIME = "00:00:00 000";
public static final String LATE_TIME = "23:59:59";
public static final String EARER_IN_THE_DAY = "yyyy-MM-dd 00:00:00 000";
public static final String LATE_IN_THE_DAY = "yyyy-MM-dd 23:59:59 999";
public static final long DAY_LONG = 24 * 60 * 60 * 1000;
public static final String YYYY_MM_DD = "yyyy-MM-dd";
private static final String WEEKLY_DATE_PATTERN = "%d_%02d";
public static final String DATE_PATEN_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static final int ONE_DAY_SECONDS = 86400;
public static final int ONE_HOURS_SECONDS = 3600;
public static final int ONE_MINUTE_SECONDS = 60;
public static final int ONE_SECOND_MILLS = 1000;
public static String getDateStringByMillisecond(String format, Long millisecond)
{
TimeZone timeZoneSH = TimeZone.getTimeZone("Asia/Shanghai");
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(timeZoneSH);
return sdf.format(new Date(millisecond));
}
/**
* @return
*/
public static String getWeek(Date date) {
return getCurrentWeekYear(date) + "_" + getCurrentWeek(date);
}
/**
* 获取当前周的年份. 即在2014年12月28日, 返回的周为2015, 因为其周取201501
*
* @return 当前周所有的年份
*/
private static int getCurrentWeekYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
int weekNum = calendar.get(Calendar.WEEK_OF_YEAR);
int year = calendar.get(Calendar.YEAR);
//use new year week num at the end of December
if ((1 == weekNum) && (Calendar.DECEMBER == calendar.get(Calendar.MONTH))) {
calendar.roll(Calendar.DAY_OF_MONTH, -7);
if (calendar.get(Calendar.WEEK_OF_YEAR) > weekNum) {
year++;
}
}
return year;
}
/**
* 获取当天日期格式
*
* @param format
* @return
*/
public static String getCurrent(String format) {
return formatDate(new Date(), format);
}
/**
* 获取当前周号
*
* @return 当前周号
*/
private static int getCurrentWeek(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
return calendar.get(Calendar.WEEK_OF_YEAR);
}
/**
* 得到某个日期在这一天中时间最早的日期对象
*
* @param date
* @return
* @throws ParseException
*/
public static Date getEarlyInTheDay(Date date) throws ParseException {
String dateString = new SimpleDateFormat(SHORT_DATE_FORMAT_STR).format(date) + " " + EARLY_TIME;
return new SimpleDateFormat(LONG_DATE_FORMAT_STR).parse(dateString);
}
/**
* 得到某天最早的时间
*
* @param date
* @return
*/
public static Date getFirstOfDay(Date date) {
String dateString = new SimpleDateFormat(EARER_IN_THE_DAY).format(date);
try {
return new SimpleDateFormat(LONG_DATE_FORMAT_STR).parse(dateString);
} catch (ParseException e) {
return null;
}
}
/**
* 得到某个日期在这一天中时间最晚的日期对象
*
* @param date
* @return
* @throws ParseException
*/
public static Date getLateInTheDay(Date date) throws ParseException {
String dateString = new SimpleDateFormat(SHORT_DATE_FORMAT_STR).format(date) + " " + LATE_TIME;
return new SimpleDateFormat(LONG_DATE_FORMAT_STR).parse(dateString);
}
/**
* 增加时间的秒数
*
* @param date 要增加的日期
* @param second 增加的时间(以秒为单位)
* @return 增加时间后的日期
*/
public static Date addSecond(Date date, int second) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.SECOND, second);
return cal.getTime();
}
/**
* 根据传入日期计算和当前日期的相差天数
*
* @param date
* @return
*/
public static long subtractNowDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
long dateTimeInMillis = calendar.getTimeInMillis();
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.setTime(new Date());
long nowTimeInMillis = nowCalendar.getTimeInMillis();
return (nowTimeInMillis - dateTimeInMillis) / (24 * 60 * 60 * 1000);
}
/**
* 获取结束日期与开始日期相差的秒数
*
* @param startDate 开始日期
* @param endDate 结束日期
* @return
*/
public static int subtractSecond(Date startDate, Date endDate) {
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
long startTimeInMillis = startCalendar.getTimeInMillis();
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
long endTimeInMillis = endCalendar.getTimeInMillis();
return (int) ((endTimeInMillis - startTimeInMillis) / 1000);
}
/*
* 获取当前日志对应的月的最大天数
* */
public static int getMaxDay(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
}
/**
* 字符串按自定格式更新
*
* @param dateString
* @param format
* @return
* @throws ParseException
*/
public static Date parserStringToDate(String dateString, String format) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.parse(dateString);
}
public static Date parse(String dateString, String format) {
Date date = null;
try {
date = parserStringToDate(dateString, format);
} catch (Exception e) {
LOG.error(e);
}
return date;
}
public static Date parse4ShortPattern(String dateString) {
return parse(dateString, SHORT_DATE_FORMAT_STR);
}
public static int getDateDistance(Date fromDate, Date toDate) throws Excepti
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
随着人们对手机依赖程度的增加,手机已经成为了绝大多数人社交、购物、休闲娱乐、学习、发表见解、获取时事新闻等需求的主要实现渠道,因此,手机APP对于各类互联网公司的重要性不言而喻,因此,越来越多的互联网公司开始重视APP的研发和升级。 当一款APP上线后,为了更好地改进这款APP,公司需要了解到这款APP的详细使用情况,例如新增用户数、活跃用户数、沉默用户数、回流用户数等;为了了解用户对于这款APP不同版本的接受程度,需要了解这款APP在用户群体中的版本分布情况;为了了解用户对于这款APP的依赖程度,我们需要获取每个用户每天使用这款APP的时长。以上这些需求的实现,都要建立在一个稳定的分布式日志采集和统计分析系统之上。 在大数据技术趋于成熟的今天,大数据技术的发展使采集海量用户信息并分析用户行为进而有目的的改进APP这一需求的实现成为可能,本项目就致力于打造一套成熟的日志数据统计分析系统,通过离线数据分析系统和实时数据分析系统两个模块的协同作用,完成APP各项指标的分析,为APP的改进与升级提供了有力的参考依据。
资源详情
资源评论
资源推荐
收起资源包目录
手机APP项目代码.zip (699个子文件)
TaildirSource.class 16KB
TaildirSource.class 16KB
DateUtils.class 15KB
ReliableTaildirEventReader.class 13KB
ReliableTaildirEventReader.class 13KB
OnlineProcess.class 7KB
SparkOnline.class 7KB
TailFile.class 7KB
TailFile.class 7KB
TaildirMatcher.class 6KB
TaildirMatcher.class 6KB
OnlineProcess$1.class 6KB
KafkaConsumer.class 6KB
SparkOnline$1.class 6KB
GenBeahavior01.class 6KB
JSONUtil.class 4KB
MonitorStopThread.class 4KB
HbaseGet.class 4KB
HBaseClient.class 3KB
UserCityPackageKey.class 3KB
ReliableTaildirEventReader$Builder.class 3KB
ReliableTaildirEventReader$Builder.class 3KB
SparkOnline$1$5$1.class 3KB
OnlineProcess$1$6$1.class 3KB
TaildirSource$idleFileCheckerRunnable.class 2KB
TaildirSource$idleFileCheckerRunnable.class 2KB
SparkOnline$1$4.class 2KB
LogCollector.class 2KB
LogCollector.class 2KB
OnlineProcess$1$5.class 2KB
LogCollector.class 2KB
LogCollector.class 2KB
OnlineProcess$1$6.class 2KB
SparkOnline$1$5.class 2KB
DateUtil.class 2KB
StringUtil.class 2KB
UploadUtil.class 2KB
PageVisitReportLogs.class 2KB
PageVisitReportLogs.class 2KB
BehaviorStatService.class 2KB
PageVisitReportLogs.class 2KB
OnlineProcess$1$2.class 2KB
SparkOnline$1$2.class 2KB
PageVisitReportLogs.class 2KB
SparkOnline$1$3.class 2KB
MonthBeginUDF.class 2KB
DayBeginUDF.class 2KB
WeekBeginUDF.class 2KB
OnlineProcess$1$3.class 2KB
TaildirSourceConfigurationConstants.class 2KB
TaildirSourceConfigurationConstants.class 2KB
OnlineProcess$1$1.class 1KB
TaildirMatcher$1.class 1KB
TaildirMatcher$1.class 1KB
SparkOnline$1$1.class 1KB
FormatTimeUDF.class 1KB
HBaseAdd.class 1KB
OnlineProcess$2.class 1KB
SparkOnline$2.class 1KB
StartupReportLogs.class 1KB
StartupReportLogs.class 1KB
OnlineProcess$1$4.class 1KB
StartupReportLogs.class 1KB
StartupReportLogs.class 1KB
OnlineProcess$3.class 1KB
SparkOnline$3.class 1KB
ErrorReportLogs.class 1KB
ErrorReportLogs.class 1KB
TaildirMatcher$2.class 1KB
TaildirMatcher$2.class 1KB
ErrorReportLogs.class 1KB
ErrorReportLogs.class 1KB
PropertiesUtil.class 1KB
UserCityStatModel.class 1002B
TaildirSource$PositionWriterRunnable.class 993B
TaildirSource$PositionWriterRunnable.class 993B
BasicLog.class 977B
BasicLog.class 977B
BasicLog.class 957B
BasicLog.class 935B
TimeTest.class 868B
MyKryoRegistrator.class 711B
TailFile$LineResult.class 633B
TailFile$LineResult.class 633B
PollableSourceConstants.class 623B
PollableSourceConstants.class 623B
BaseModel.class 316B
ReliableTaildirEventReader$1.class 276B
ReliableTaildirEventReader$1.class 276B
TaildirSource$1.class 237B
TaildirSource$1.class 237B
data-processing.iml 21KB
common.iml 21KB
log-collector-web.iml 5KB
log-collector-web.iml 5KB
taildirsource.iml 5KB
taildirsource.iml 5KB
data_producer.iml 2KB
log-collector-common.iml 2KB
log-collector-common.iml 2KB
共 699 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
秃顶
- 粉丝: 785
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0