java时间格式大全java.util.*;importjava.text.*;importjava.util.Calendar;publicclassVeDate{/***//***获取现在时间**@return返回时间类型yyyy-MM-ddHH:mm:ss*/publicstaticDategetNowDate(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);StringdateString=formatter.format(currentTime);ParsePositionpos=newParsePosition(8);DatecurrentTime_2=formatter.parse(dateString,pos);returncurrentTime_2;}/***//***获取现在时间**@return返回短时间格式yyyy-MM-dd*/publicstaticDategetNowDateShort(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-dd);StringdateString=formatter.format(currentTime);ParsePositionpos=newParsePosition(8);DatecurrentTime_2=formatter.parse(dateString,pos);returncurrentTime_2;}/***//***获取现在时间**@return返回字符串格式yyyy-MM-ddHH:mm:ss*/publicstaticStringgetStringDate(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);StringdateString=formatter.format(currentTime);returndateString;}/***//***获取现在时间**@return返回短时间字符串格式yyyy-MM-dd*/publicstaticStringgetStringDateShort(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-dd);StringdateString=formatter.format(currentTime);returndateString;}/***//***获取时间小时:分;秒HH:mm:ss**@return*/publicstaticStringgetTimeShort(){SimpleDateFormatformatter=newSimpleDateFormat(HH:mm:ss);DatecurrentTime=newDate();StringdateString=formatter.format(currentTime);returndateString;}/***//***将长时间格式字符串转换为时间yyyy-MM-ddHH:mm:ss**@paramstrDate*@return*/publicstaticDatestrToDateLong(StringstrDate){SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);ParsePositionpos=newParsePosition(0);Datestrtodate=formatter.parse(strDate,pos);returnstrtodate;}/***//***将长时间格式时间转换为字符串yyyy-MM-ddHH:mm:ss**@paramdateDate*@return*/publicstaticStringdateToStrLong(java.util.DatedateDate){SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);StringdateString=formatter.format(dateDate);returndateString;}/***//***将短时间格式时间转换为字符串yyyy-MM-dd**@paramdateDate*@paramk*@return*/publicstaticStringdateToStr(java.util.DatedateDate){SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-dd);StringdateString=formatter.format(dateDate);returndateString;}/***//***将短时间格式字符串转换为时间yyyy-MM-dd**@paramstrDate*@return*/publicstaticDatestrToDate(StringstrDate){SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-dd);ParsePositionpos=newParsePosition(0);Datestrtodate=formatter.parse(strDate,pos);returnstrtodate;}/***//***得到现在时间**@return*/publicstaticDategetNow(){DatecurrentTime=newDate();returncurrentTime;}/***//***提取一个月中的最后一天**@paramday*@return*/publicstaticDategetLastDate(longday){Datedate=newDate();longdate_3_hm=date.getTime()-3600000*34*day;Datedate_3_hm_date=newDate(date_3_hm);returndate_3_hm_date;}/***//***得到现在时间**@return字符串yyyyMMddHHmmss*/publicstaticStringgetStringToday(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyyMMddHHmmss);StringdateString=formatter.format(currentTime);returndateString;}/***//***得到现在小时*/publicstaticStringgetHour(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);StringdateString=formatter.format(currentTime);Stringhour;hour=dateString.substring(11,13);returnhour;}/***//***得到现在分钟**@return*/publicstaticStringgetTime(){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);StringdateString=formatter.format(currentTime);Stringmin;min=dateString.substring(14,16);returnmin;}/***//***根据用户传入的时间表示格式,返回当前时间的格式如果是yyyyMMdd,注意字母y不能大写。**@paramsformat*yyyyMMddhhmmss*@return*/publicstaticStringgetUserDate(Stringsformat){DatecurrentTime=newDate();SimpleDateFormatformatter=newSimpleDateFormat(sformat);StringdateString=formatter.format(currentTime);returndateString;}/***//***二个小时时间间的差值,必须保证二个时间都是HH:MM的格式,返回字符型的分钟*/publicstaticStringgetTwoHour(Stringst1,Stringst2){String[]kk=null;String[]jj=null;kk=st1.split(:);jj=st2.split(:);if(Integer.parseInt(kk[0])Integer.parseInt(jj[0]))return0;else{doubley=Double.parseDouble(kk[0])+Double.parseDouble(kk[1])/60;doubleu=Double.parseDouble(jj[0])+Double.parseDouble(jj[1])/60;if((y-u)0)returny-u+;elsereturn0;}}/***//***得到二个日期间的间隔天数*/publicstaticStringgetTwoDay(Stringsj1,Stringsj2){SimpleDateFormatmyFormatter=newSimpleDateFormat(yyyy-MM-dd);longday=0;try{java.util.Datedate=myFormatter.parse(sj1);java.util.Datemydate=myFormatter.parse(sj2);day=(date.getTime()-mydate.getTime())/(24*60*60*1000);}catch(Exceptione){return;}returnday+;}/***//***时间前推或后推分钟,其中JJ表示分钟.*/publicstaticStringgetPreTime(Stringsj1,Stringjj){SimpleDateFormatformat=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);Stringmydate1=;try{Datedate1=format.parse(sj1);longTime=(date1.getTime()/1000)+Integer.parseInt(jj)*60;date1.setTime(Time*1000);mydate1=format.format(date1);}catch(Exceptione){}returnmydate1;}/***//***得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数*/publicstaticStringgetNextDay(Stringnowdate,Stringdelay){try{SimpleDateFormatformat=newSimpleDateFormat(yyyy-MM-dd);Stringmdate=;Dated=strToDate(nowdate);longmyTime