📄 jmendateutil.java
字号:
String strDate3 = "0";
if (strbuffInputDate.length() == 10
|| strbuffInputDate.substring(4, 5).equals("/")) {
strbuffInputDate.delete(0, 2);
}
//6寘柍偗傟偽柍忦審偵僄儔乕
if (strbuffInputDate.length() == 8
|| strbuffInputDate.substring(2, 3).equals("/")) {
strbuffDate.append(strbuffInputDate.substring(0, 2));
strbuffInputDate.delete(0, 3);
strbuffDate.append(strbuffInputDate.substring(0, 2));
strbuffInputDate.delete(0, 3);
strbuffDate.append(strbuffInputDate.substring(0, 2));
for (int i = 0; i < strbuffDate.length(); i++) {
char charData = strbuffDate.charAt(i);
if ((charData < '0') || (charData > '9')) {
strDate3 = "0";
}
}
strDate3 = strbuffDate.toString();
}
return strDate3;
}
/**
* 寧傪儘乕儖偟傑偡
*
* @return 儘乕儖屻偺抣
* @param String
* strDate(yyyyMMdd)
* @param int
* intMonth 儘乕儖抣 寧屻 = + , 寧慜 = -
* @return String 儘乕儖屻偺抣
*/
public static String rollMonth(String strDate, int intMonth) {
String strDay = "0";
if (strDate != null && strDate.length() == 8) {
int year = Integer.parseInt(strDate.substring(0, 4));
int month = Integer.parseInt(strDate.substring(4, 6)) - 1;
int day = Integer.parseInt(strDate.substring(6, 8));
Calendar c = Calendar.getInstance();
DecimalFormat df = new DecimalFormat("00");
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DATE, day);
c.add(Calendar.MONTH, intMonth);
strDay =
c.get(Calendar.YEAR)
+ df.format(c.get(Calendar.MONTH) + 1)
+ df.format(c.get(Calendar.DATE));
}
return strDay;
}
/**
* <H3>擔晅曄姺傪愝掕偡傞</H3>
*
* @param strDate
* 曄姺偡傞暥帤楍 20050825 佀 050825
*
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String Str2Date4(String strDate) {
if (strDate == null || strDate.equals("")) {
return "";
}
if (strDate.length() == 8) {
strDate = strDate.substring(2);
} else {
strDate = "";
}
return strDate;
}
/**
* 擔晅曄姺傪愝掕偡傞
*
* @param strData
* 擔晅
* @param userInfo
* 儐乕僓乕忣曬
* @return newDataString --巊梡椺-- 0508 佀 200508
*
*/
public static String setDateString2(String strDate) {
String strNewDate = "";
if (strDate != null && strDate.length() == 4) {
//敿妏悢帤僠僃僢僋
if (JMCheckType.isHalfNumber(strDate)) {
int intYearkb = PATTERN_YEARKB;
int intYear = Integer.parseInt(strDate.substring(0, 2));
if (intYear >= intYearkb) {
strNewDate =
PATTERN_DB_REGIST_DATE_19YYMMDD + strDate;
} else {
strNewDate =
PATTERN_DB_REGIST_DATE_20YYMMDD + strDate;
}
}
}
return strNewDate;
}
/**
* <H3>暥帤楍乮YYYYMM乯/乮YYYYMMDD乯傪擔晅宍幃(YY/MM)傊曄姺偡傞</H3>
*
* @param strDate
* 曄姺偡傞暥帤楍
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String Str2Date5(String strDate) {
if (strDate == null || strDate.equals("")) {
return "";
}
if (strDate.length() == 8) {
strDate = strDate.substring(0,6);
}
if (strDate.length() == 6) {
StringBuffer stbDate = new StringBuffer(strDate.substring(2));
stbDate.insert(2, "/");
strDate = stbDate.toString();
} else {
return strDate;
}
return strDate;
}
/**
* <H3>暥帤楍乮YY/MM乯傪擔晅宍幃(YYYYMM00)傊曄姺偡傞</H3>
*
* @param strDate
* 曄姺偡傞暥帤楍
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String Str2Date6(String strDate) {
if (strDate == null || strDate.equals("")) {
return "";
}
String year = strDate.substring(0, 2);
String month = strDate.substring(3, 5);
String date = year + month + PATTERN_DB_REGIST_DATE_YYMM00;
// 6寘偺擔晅乕亜 8寘偺擔晅
if (date.length() == 6) {
date = setDateString(date);
}
return date;
}
/**
* 擔晅宍幃乮YY/MM/DD乯傪暥帤楍乮YYYYMMDD乯傊曄姺
*
* @param strDate
* 曄姺偟偨偄僨乕僞
* @return int 曄姺偝傟偨僨乕僞
*/
public static String Date4Str(String strDate) {
String strDate4 = strDate;
if (strDate4 != null && !"".equals(strDate4)) {
//6寘柍偗傟偽柍忦審偵僄儔乕
if (strDate4.length() == 8
&& strDate4.substring(2, 3).equals("/")) {
strDate4 = Date3Str(strDate4);
}
// 6寘偺擔晅乕亜 8寘偺擔晅
if (strDate4.length() == 6) {
strDate4 = setDateString(strDate4);
}
}
return strDate4;
}
/**
* 擔晅曄姺傪愝掕偡傞
*
* @param strData丂擔晅
*
* @return newDataString --巊梡椺-- 200508 佀 20050800
*
*
*/
public static String addDateString(String strDate) {
String strNewDate = "";
if (strDate != null && strDate.length() == 6) {
//敿妏悢帤僠僃僢僋
if (JMCheckType.isHalfNumber(strDate)) {
strNewDate = strDate + PATTERN_DB_REGIST_DATE_YYMM00;
} else {
return strDate;
}
} else {
return strDate;
}
return strNewDate;
}
/**
* <H3>暥帤楍乮YY/MM乯傪擔晅宍幃(YYYYMM)傊曄姺偡傞</H3>
*
* @param strDate
* 曄姺偡傞暥帤楍
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String Str2Date7(String strDate) {
if (strDate == null || strDate.equals("")) {
return "";
}
if (strDate.length() != 5) {
return strDate;
}
String year = strDate.substring(0, 2);
String month = strDate.substring(3, 5);
String date = year + month;
if (JMCheckType.isHalfNumber(date)) {
int intYear = Integer.parseInt(year);
if (intYear >= PATTERN_YEARKB) {
date = PATTERN_DB_REGIST_DATE_19YYMMDD + date;
} else {
date = PATTERN_DB_REGIST_DATE_20YYMMDD + date;
}
}
return date;
}
/**
* 擔晅曄姺傪愝掕偡傞
*
* @param strDate
* 擔晅
* @return newDataString --巊梡椺-- 20050828 佀 0508
* 050828 佀 0508
*/
public static String setDateToYyMm(String strDate) {
String strNewDate = "";
if (strDate != null && strDate.length() >= 6) {
//敿妏悢帤僠僃僢僋
if (JMCheckType.isHalfNumber(strDate)) {
strNewDate = strDate.substring(2, 6);
}
}
return strNewDate;
}
/**
* <H3>摉寧偺FirstDay傪庢摼偡傞丅</H3>
*
* @param 側偟
*
* @return 摉寧偺FirstDay
*
*/
public String getMonthFirstDay() {
String strDay = "";
Calendar cal = Calendar.getInstance();
strDay =
JMCommonUtil.fillInLeft(
String.valueOf(cal.getActualMinimum(Calendar.DAY_OF_MONTH)),
'0',
2);
strDay =
nowDate(PATTERN_DB_REGIST_DATE6).substring(0, 4)
+ strDay;
return strDay;
}
/**
* <H3>摉寧偺LastDay傪庢摼偡傞丅</H3>
*
* @param 側偟
*
* @return 摉寧偺LastDay
*
*/
public String getMonthLastDay() {
String strDay = "";
Calendar cal = Calendar.getInstance();
strDay =
JMCommonUtil.fillInLeft(
String.valueOf(cal.getActualMaximum(Calendar.DAY_OF_MONTH)),
'0',
2);
strDay =
nowDate(PATTERN_DB_REGIST_DATE6).substring(0, 4)
+ strDay;
return strDay;
}
/**
* 擔晅曄姺傪愝掕偡傞
*
* @param intDate
* 擔晅
* @return newDataString --巊梡椺-- 200508 佀 05/08
*/
public static String int2Date1(int intDate) {
String strNewDate = "";
if (intDate != 0) {
strNewDate = Str2Date5(String.valueOf(intDate));
}
return strNewDate;
}
/**
* <H3>暥帤楍乮YYYYMM乯傪擔晅宍幃(YYYY/MM)傊曄姺偡傞</H3>
*
* @param strDate
* 曄姺偡傞暥帤楍
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String Str2Date8(String strDate) {
if (strDate == null || strDate.equals("")) {
return "";
}
if (strDate.length() == 6) {
StringBuffer strTemp = new StringBuffer(strDate);
strTemp.insert(4, "/");
strDate = strTemp.toString();
} else {
return strDate;
}
return strDate;
}
/**
* <H3>寧枛擔偺庢摼</H3>
*
* @param strYearMonth
* 擭寧(200509 / 20050910)
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String getMaxDay(String strYearMonth) {
String strDate = "";
if(strYearMonth!=null && strYearMonth.length() >= 6){
int year = Integer.parseInt(strYearMonth.substring(0,4));
int month = Integer.parseInt(strYearMonth.substring(4,6));
Calendar c = Calendar.getInstance();
DecimalFormat df = new DecimalFormat("00");
c.set(Calendar.YEAR,year);
c.set(Calendar.MONTH,month);
c.set(Calendar.DATE,1);
c.add(Calendar.DATE,-1);
strDate = c.get(Calendar.YEAR) +
df.format(c.get(Calendar.MONTH) + 1) +
df.format(c.get(Calendar.DATE));
}
return strDate;
}
/**
* <H3>暥帤楍乮YY/MM乯傪擔晅宍幃(YYMM)傊曄姺偡傞</H3>
*
* @param strDate
* 曄姺偡傞暥帤楍
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String Str4Date4(String strDate) {
if (strDate == null || strDate.equals("")) {
return "";
}
if (strDate.length() != 5) {
return strDate;
}
String year = strDate.substring(0, 2);
String month = strDate.substring(3, 5);
String date = year + month;
if (!JMCheckType.isHalfNumber(date)) {
return "";
}
return date;
}
/**
* <H3>巜掕擔偺庢摼</H3>
*
* @param strDate丂張棟擔晅(20050910/050910)
* @param rollDay丂巜掕擔
*
* @return String 曄姺屻偺擔晅宍幃偺暥帤楍
*/
public static String rollDay(String strDate,int rollDay) {
String date = "";
String strDate2 = "";
if(strDate==null || (strDate.length()!=6 && strDate.length()!=8)){
return "";
}
if (!JMCheckType.isHalfNumber(date)) {
return "";
}
if(strDate.length() == 6){
strDate2 = strDate;
strDate = setDateString(strDate);
}
int year = Integer.parseInt(strDate.substring(0,4));
int month = Integer.parseInt(strDate.substring(4,6)) - 1;
int day = Integer.parseInt(strDate.substring(6,8));
if(rollDay != 0){
Calendar c = Calendar.getInstance();
DecimalFormat df = new DecimalFormat("00");
c.set(Calendar.YEAR,year);
c.set(Calendar.MONTH,month);
c.set(Calendar.DATE,day);
c.add(Calendar.DATE,rollDay);
date = c.get(Calendar.YEAR) + df.format(c.get(Calendar.MONTH) + 1) +
df.format(c.get(Calendar.DATE));
}
if(strDate2.length() == 6){
date = date.substring(2);
}
return date;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -