/*****************************************************
* 函数名: GetCurrentDate
* 机能概要: 获取当前的日期
*
* 参数: nFormat返回的格式
* 0:"YYYYMMDD" 7:"DD/MM/YYYY"
* 1:"YYYY/MM/DD" 8:"DD-MM-YYYY"
* 2:"YYYY-MM-DD" 9:"DDMMYY"
* 3:"YYMMDD" 10:"DD/MM/YY"
* 4:"YY/MM/DD" 11:"DD-MM-YY"
* 5:"YY-MM-DD" 12:"YYYY年MM月DD日"
* 6:"DDMMYYYY" 13:"YY年MM月DD日"
* 返回值: 指定格式的当前日期
*********************************************************/ public static String GetCurrentDate(int nFormat){
String strReturnValue = "";
String strYear, strMonth, strDate;
GregorianCalendar GreDate = new GregorianCalendar();
strYear = new Integer(GreDate.get(GreDate.YEAR)).toString ();
strMonth = new Integer(GreDate.get(GreDate.MONTH) + 1).toString ();
strDate = new Integer(GreDate.get(GreDate.DATE)).toString ();
strReturnValue = GetFormatedDate(strYear,strMonth,strDate,nFormat);
return strReturnValue;
}
/*****************************************************
* 函数名: GetFormatedDate
* 机能概要: 按照指定的格式转换日期
*
* 参数: strYear有效的年份
* strMonth有效的月份
* strDate有效的日
* nFormat指定的返回格式
* 0:"YYYYMMDD" 7:"DD/MM/YYYY"
* 1:"YYYY/MM/DD" 8:"DD-MM-YYYY"
* 2:"YYYY-MM-DD" 9:"DDMMYY"
* 3:"YYMMDD" 10:"DD/MM/YY"
* 4:"YY/MM/DD" 11:"DD-MM-YY"
* 5:"YY-MM-DD" 12:"YYYY年MM月DD日"
* 6:"DDMMYYYY" 13:"YY年MM月DD日"
* 返回值: 指定格式的日期
*********************************************************/ public static String GetFormatedDate(String strYear, String strMonth,
String strDate, int nFormat)
{
String strReturnValue = "";
switch(nFormat){
case 0:
strReturnValue = SupplyLength(strYear,4) +
SupplyLength(strMonth,2) +
SupplyLength(strDate,2);
break;
case 1:
strReturnValue = SupplyLength(strYear,4) + "/" +
SupplyLength(strMonth,2) + "/" +
SupplyLength(strDate,2);
break;
case 2:
strReturnValue = SupplyLength(strYear,4) + "-" +
SupplyLength(strMonth,2) + "-" +
SupplyLength(strDate,2);
break;
case 3:
strReturnValue = SupplyLength(strYear,4).substring (2) +
SupplyLength(strMonth,2) +
SupplyLength(strDate,2);
break;
case 4:
strReturnValue = SupplyLength(strYear,4).substring (2) + "/" +
SupplyLength(strMonth,2) + "/" +
SupplyLength(strDate,2);
break;
case 5:
strReturnValue = SupplyLength(strYear,4).substring (2) + "-" +
SupplyLength(strMonth,2) + "-" +
SupplyLength(strDate,2);
break;
case 6:
strReturnValue = SupplyLength(strDate,2) +
SupplyLength(strMonth,2) +
SupplyLength(strYear,4);
break;
case 7:
strReturnValue = SupplyLength(strDate,2) + "/" +
SupplyLength(strMonth,2) + "/" +
SupplyLength(strYear,4);
break;
case 8:
strReturnValue = SupplyLength(strDate,2) + "-" +
SupplyLength(strMonth,2) + "-" +
SupplyLength(strYear,4);
break;
case 9:
strReturnValue = SupplyLength(strDate,2) +
SupplyLength(strMonth,2) +
SupplyLength(strYear,4).substring (2);
break;
case 10:
strReturnValue = SupplyLength(strDate,2) + "/" +
SupplyLength(strMonth,2) + "/" +
SupplyLength(strYear,4).substring (2);
break;
case 11:
strReturnValue = SupplyLength(strDate,2) + "-" +
SupplyLength(strMonth,2) + "-" +
SupplyLength(strYear,4).substring (2);
break;
case 12:
strReturnValue = SupplyLength(strYear, 4) + "年" +
SupplyLength(strMonth, 2) + "月" +
SupplyLength(strDate, 2) + "日";
break;
case 13:
strReturnValue = SupplyLength(strYear, 4).substring(2) + "年" +
SupplyLength(strMonth, 2) + "月" +
SupplyLength(strDate, 2) + "日";
break;
}
return strReturnValue;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12379366/viewspace-85533/
,如需转载,请注明出处,否则将追究法律责任。