package com.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DateUtil {
public DateUtil(){}
/**
* @see 取得当前日期(格式为:yyyy-MM-dd)
* @return String
*/
public String GetDate()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String sDate = sdf.format(new Date());
return sDate;
}
/**
* @see 取得当前时间(格式为:yyy-MM-dd HH:mm:ss)
* @return String
*/
public static String GetDateTime()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sDate = sdf.format(new Date());
return sDate;
}
/**
* @see 按指定格式取得当前时间()
* @return String
*/
public String GetTimeFormat(String strFormat)
{
SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
String sDate = sdf.format(new Date());
return sDate;
}
/**
* @see 取得指定时间的给定格式()
* @return String
* @throws ParseException
*/
public String SetDateFormat(String myDate,String strFormat) throws ParseException
{
SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
String sDate = sdf.format(sdf.parse(myDate));
return sDate;
}
public String FormatDateTime(String strDateTime, String strFormat)
{
String sDateTime = strDateTime;
try {
Calendar Cal = parseDateTime(strDateTime);
SimpleDateFormat sdf = null;
sdf = new SimpleDateFormat(strFormat);
sDateTime = sdf.format(Cal.getTime());
} catch (Exception e) {
}
return sDateTime;
}
public static Calendar parseDateTime(String baseDate)
{
Calendar cal = null;
cal = new GregorianCalendar();
int yy = Integer.parseInt(baseDate.substring(0, 4));
int mm = Integer.parseInt(baseDate.substring(5, 7)) - 1;
int dd = Integer.parseInt(baseDate.substring(8, 10));
int hh = 0;
int mi = 0;
int ss = 0;
if(baseDate.length() > 12)
{
hh = Integer.parseInt(baseDate.substring(11, 13));
mi = Integer.parseInt(baseDate.substring(14, 16));
ss = Integer.parseInt(baseDate.substring(17, 19));
}
cal.set(yy, mm, dd, hh, mi, ss);
return cal;
}
public int getDay(String strDate)
{
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.DATE);
}
public int getMonth(String strDate)
{
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.MONTH) + 1;
}
public int getWeekDay(String strDate)
{
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.DAY_OF_WEEK);
}
public String getWeekDayName(String strDate)
{
String mName[] = {
"日", "一", "二", "三", "四", "五", "六"
};
int iWeek = getWeekDay(strDate);
iWeek = iWeek - 1;
return "星期" + mName[iWeek];
}
public int getYear(String strDate)
{
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.YEAR) + 1900;
}
public String DateAdd(String strDate, int iCount, int iType)
{
Calendar Cal = parseDateTime(strDate);
int pType = 0;
if(iType == 0)
{
pType = 1;
} else
if(iType == 1)
{
pType = 2;
} else
if(iType == 2)
{
pType = 5;
} else
if(iType == 3)
{
pType = 10;
} else
if(iType == 4)
{
pType = 12;
} else
if(iType == 5)
{
pType = 13;
}
Cal.add(pType, iCount);
SimpleDateFormat sdf = null;
if(iType <= 2)
sdf = new SimpleDateFormat("yyyy-MM-dd");
else
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sDate = sdf.format(Cal.getTime());
return sDate;
}
public String DateAdd(String strOption, int iDays, String strStartDate)
{
if(!strOption.equals("d"));
return strStartDate;
}
public int DateDiff(String strDateBegin, String strDateEnd, int iType)
{
Calendar calBegin = parseDateTime(strDateBegin);
Calendar calEnd = parseDateTime(strDateEnd);
long lBegin = calBegin.getTimeInMillis();
long lEnd = calEnd.getTimeInMillis();
int ss = (int)((lBegin - lEnd) / 1000L);
int min = ss / 60;
int hour = min / 60;
int day = hour / 24;
if(iType == 0)
return hour;
if(iType == 1)
return min;
if(iType == 2)
return day;
else
return -1;
}
/*****************************************
* @功能 判断某年是否为闰年
* @return boolean
* @throws ParseException
****************************************/
public boolean isLeapYear(int yearNum){
boolean isLeep = false;
/**判断是否为闰年,赋值给一标识符flag*/
if((yearNum % 4 == 0) && (yearNum % 100 != 0)){
isLeep = true;
} else if(yearNum % 400 ==0){
isLeep = true;
} else {
isLeep = false;
}
return isLeep;
}
/*****************************************
* @功能 计算当前日期某年的第几周
* @return interger
* @throws ParseException
****************************************/
public int getWeekNumOfYear(){
Calendar calendar = Calendar.getInstance();
int iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
return iWeekNum;
}
/*****************************************
* @功能 计算指定日期某年的第几周
* @return interger
* @throws ParseException
****************************************/
public int getWeekNumOfYearDay(String strDate ) throws ParseException{
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date curDate = format.parse(strDate);
calendar.setTime(curDate);
int iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
return iWeekNum;
}
/*****************************************
* @功能 计算某年某周的开始日期
* @return interger
* @throws ParseException
****************************************/
public String getYearWeekFirstDay(int yearNum,int weekNum) throws ParseException {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearNum);
cal.set(Calendar.WEEK_OF_YEAR, weekNum);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
//分别取得当前日期的年、月、日
String tempYear = Integer.toString(yearNum);
String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1);
String tempDay = Integer.toString(cal.get(Calendar.DATE));
String tempDate = tempYear + "-" +tempMonth + "-" + tempDay;
return SetDateFormat(tempDate,"yyyy-MM-dd");
}
/*****************************************
* @功能 计算某年某周的结束日期
* @return interger
* @throws ParseException
****************************************/
public String getYearWeekEndDay(int yearNum,int weekNum) throws ParseException {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearNum);
cal.set(Calendar.WEEK_OF_YEAR, weekNum + 1);
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
//分别取得当前日期的年、月、日
String tempYear = Integer.toString(yearNum);
String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1);
String tempDay = Integer.toString(cal.get(Calendar.DATE));
String tempDate = tempYear + "-" +tempMonth + "-" + tempDay;
return SetDateFormat(tempDate,"yyyy-MM-dd");
}
/*****************************************
* @功能 计算某年某月的开始日期
* @return interger
* @throws ParseException
****************************************/
public String getYearMonthFirstDay(int yearNum,int monthNum) throws ParseException {
//分别取得当前日期的年、月、日
String tempYear = Integer.toString(yearNum);
String tempMonth = Integer.toString(monthNum);
String tempDay = "1";
String tempDate = tempYear + "-" +tempMonth + "-" + tempDay;
return SetDateFormat(tempDate,"yyyy-MM-dd");
}
/*****************************************
* @功能 计算某年某月的结束日期
* @return interger
* @throws ParseException
****************************************/
public String getYearMonthEndDay(int yearNum,int monthNum) throws ParseException {
//分别取得当前日期的年、月、日
String tempYear = Integer.toString(yearNum);
String tempMonth = Integer.toString(monthNum);
String tempDay = "31";
if (tempMonth.equals("1") || tempMonth.equals("3") || tempMonth.equals("5") || tempMonth.equals("7") ||tempMonth.equals("8") || tempMonth.equals("10") ||tempMonth.equals("12")) {
tempDay = "31";
}
if (tempMonth.equals("4") || tempMonth.equals("6") || tempMonth.equals("9")||tempMonth.equals("11")) {
tempDay = "30";
}
if (tempMonth.equals("2")) {
if (isLeapYear(yearNum)) {
tempDay = "29";
} else {
tempDay = "28";
}
}
//System.out.println("tempDay:" + tempDay);
String tempDate = tempYear + "-" +tempMonth + "-" + tempDay;
return SetDateFormat(tempDate,"yyyy-MM-dd");
}
}
分享到:
相关推荐
pimpinella_3cd_01_0716
FIB English learning
X86-jq安装包
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
大圣挪车小程序1.3.5 前端
Manus.im 产品及开发团队研究报告.pdf
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
sun_3ck_01a_0918
下载 1. 单击“立即下载”,以下载该文件。 2. 出现“文件下载”窗口后,单击“保存”,以将文件保存到硬盘。 安装 1. 浏览至文件下载目标位置并双击新下载的文件。 2. 仔细阅读对话窗口中显示的发布信息。 3. 下载并安装对话窗口中标识的任何必备项,然后再继续。 4. 单击“Install”(安装)按钮。 5. 按照其余提示执行更新。 安装 1. 将解压的文件复制到可访问Windows的介质。 2. 将系统重新引导至Windows操作系统。 3. 打开“服务器管理器”->“设备管理器”->“存储控制器”,然后单击“PERC控制器”。 5. 单击“更新驱动程序软件”,并按照提示更新驱动程序。 4. 重新引导系统以使更改生效。
支持所有操作系统一键安装。
matlab程序代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
swanson_01_1106
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
sun_3ck_01_0919
各城市方言距离数据-中山大学岭南学院产业与区域经济研究中心 方言距离是指两种或多种方言之间的相似程度或差异程度。参考中山大学岭南学院产业与区域经济研究中心的刘毓芸等(2015)文献。他们基于方言树图,并参考《汉语方言大词典》和《中国语言地图集》对方言的划分,将汉语方言从宽泛到具体分为以下几个层级:汉语→方言大区→方言区→方言片。为了量化县与县之间的方言差异,他们采用了一种赋值方法: 若它们分属不同方言大区,则距离为3。: 若两个县同属一个方言片,则它们之间的方言距离为0; 若两个县属于同一方言区但不同方言片,则距离为1; 若它们属于同一方言大区但不同方言区,则距离为2; 方言距离是一个反映方言之间相似程度或差异程度的重要指标,它在语音识别、方言研究等领域具有广泛的应用价值。 参考文献:[1]刘毓芸, 徐现祥, 肖泽凯. 2015. 劳动力跨方言流动的倒U型模式[J]. 经济研究, 50(10): 134-146+162. 指标 语系、语族、方言大区、方言区/语支、方言片/语种、Supergroup、Dialect、group、Sub-dialect、groupPref_1、Pref_2、DiaDist、PrefCode_1、PrefCode_2等等。
基于PCA算法的人脸识别MATLAB源码
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
lim_3ck_01a_0518