欢迎来到天天文库
浏览记录
ID:35478079
大小:55.23 KB
页数:6页
时间:2019-03-25
《java处理日期问题的技巧》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、publicclassBusinessDate{publicBusinessDate(){*取得当天日期,格式2009-02-11*@return*/publicstaticStringgetTodayO{java.text.SimpleDateFormatsdf=newjava.text.SimpleDateFormat(Hyyyy-MM-ddn);Calendarcl=newGregorianCalendar();returnsdf.format(cl.getTime());*取得当天日期时间,格式2009-02-1123:9:21*@ret
2、urn*/publicstaticStringgetTodaytime(){Calendarcl=newGregorianCalendar();returngetTodayO+““+cl.get(Calendar.HOUR_OF_DAY)+”:”+cl.get(Calendar.MINUTE)+“:”+cl.get(Calendar.SECOND)+””;*取得当前时间,格式23:12:20*@return*/publicstaticStringgetTime(){Calendarcl=newGregorianCalendar();returnc
3、l.get(Calendar.HOUR_OF_DAY)++cl.get(Calendar.MINUTE)++cl.get(Calendar.SECOND)+““;*取得当前小时*@return*/publicstaticintgetHour(){Calendarcl=newGregorianCalendar();returncl.get(CaIendar.HOUR_OF_DAY);*取得当前日期格式为20090211@return*/publicstaticStringgetNoFormatTodayO{java.text.SimpleDateF
4、ormatsdf=newjava.text.SimpleDateFormat(HyyyyMMddn);Calendarcl=newGregorianCalendar();returnsdf.format(cl.getTime());*取得当前时间格式为231611@return*/publicstaticStringgetNoFormatTime(){java.text.SimpleDateFormatsdf=newjava.text.SimpleDateFormat(nHHmmssn);Calendarcl=newGregorianCalend
5、ar();returnsdf.format(cLgetTime());}*取得当前年份@return*/publicstaticStringgetYear(){returnBusinessDate.getNoFormatToday().substring(0,4);}*取得当前月份*@return*/publicstaticStringgetMonth(){returnBusinessDate.getNoFormatToday().substring(4,6);/***取得当前日*@return*/publicstaticStringgetDay
6、O{returnBusinessDate.getNoFormatToday().substring(6,8);*返回昨天的日期格式2009-02-10*@return*/publicstaticStringgetYesterdayO{StringstrYesterday=,M';Calendarcale=null;cale=newGregorianCalendar();cale.add(Calendar.DATE,-1);strYesterday=BusinessDate.getStrByCalendar(cale);returnstrYeste
7、rday;1publicstaticStringgetStrByCalendar(Calendarcale){return(newjava.text.SimpleDateFormat(Myyyy-MM-ddn)).format(cale.getTime());}/***日期字符串的格式转换,例如”2009・02・11”转换为2009年2月11日*@paramsDate*@return*/publicstaticStringgetChnDateString(StringsDate){if(sDate==null){returnnull;1sDate
8、=sDate.trim();if(sDate.length()==7){sDate+=”-01";}StringTokenizerst=
此文档下载收益归作者所有