文档详情

JAVA各种日期算法大全.docx

发布:2019-01-02约4.8万字共33页下载文档
文本预览下载声明
public class DateTime { //----------------------------------------------------------------------------------- /** * 得到系统当前年的数据字符串 * @return strYear 返回的结果,格式 yyyy ,String 类型 * @exception 得到系统当前年的数据字符串错误 */ public String getYear() { String strYear=; Date currentDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat (yyyy); strYear= formatter.format(currentDate); return strYear; } //----------------------------------------------------------------------------------- /** * 得到系统当前年月数据字符串 * @return strYearMonth 返回的结果,格式 yyyy-MM,String 类型 * @exception 得到系统当前年月数据字符串错误 */ public String getYearMonth() { String strYearMonth=; Date currentDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat (yyyy-MM); strYearMonth= formatter.format(currentDate); return strYearMonth; } //----------------------------------------------------------------------------------- /** * 得到系统当前年月日数据字符串 * @return strCurrentDate 返回的结果,格式 yyyy-MM-dd,String 类型 * @exception 得到系统当前年月日数据字符串错误 */ public static String getDate() { String strCurrentDate=; Date currentDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat (yyyy-MM-dd); strCurrentDate= formatter.format(currentDate); return strCurrentDate; } //----------------------------------------------------------------------------------- /** * 得到系统当前小时,秒,分数据字符串 * @return strCurrentTime 返回的结果,格式 HH:mm:ss,String 类型 * @exception 得到系统当前小时,秒,分数据字符串错误 */ public String getTime() { String strCurrentTime=; Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat (HH:mm:ss); strCurrentTime= formatter.format(currentTime); return strCurrentTime; } //--------------------------------------------------------------------------------
显示全部
相似文档