(相关资料图)
博主发表的文章,有的是自己原创,有的是这些年本人从网上积累的,方便大家查询。
[[178763]]
importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;/***时间工具类*Createdbyzybon2016年3月15日.*/publicclassDateTimeUtil{/***获取当前系统的日期和时间,返回格式为:2015-10-2314:00:46**@returnString*/publicstaticStringgetDateTime(){SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");Stringstr=df.format(newDate());returnstr;}/***获取当前系统的日期和时间,返回格式为:20151023140046**@return*/publicstaticStringgetDateTimeExt(){SimpleDateFormatdf=newSimpleDateFormat("yyyyMMddHHmmss");Stringstr=df.format(newDate());returnstr;}/***获取当前系统的日期,返回格式为:2015-10-23**@returnString*/publicstaticStringgetDate(){SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-dd");Stringstr=df.format(newDate());returnstr;}/***获取当前系统的日期,返回格式为:2015/10/23**@return*/publicstaticStringgetDateExt(){SimpleDateFormatdf=newSimpleDateFormat("yyyy/MM/dd");Stringstr=df.format(newDate());returnstr;}/***当前周**@return*/publicstaticStringgetWeek(){Calendarcd=Calendar.getInstance();StringstrWeek=String.valueOf(cd.get(Calendar.WEEK_OF_YEAR));returnstrWeek;}/***当前年**@return*/publicstaticStringgetYear(){Calendarcd=Calendar.getInstance();StringstrYear=String.valueOf(cd.get(Calendar.YEAR));returnstrYear;}/***当前月**@return*/publicstaticStringgetMonth(){Calendarcd=Calendar.getInstance();StringstrMonth=String.valueOf(cd.get(Calendar.MONTH)+1);returnstrMonth;}/***获取日期**@return*/publicstaticStringgetDay(){Calendarcd=Calendar.getInstance();StringstrDay=String.valueOf(cd.get(Calendar.DAY_OF_MONTH));returnstrDay;}/***获取当前时间差**@returnString*/publicstaticlongdeltaT(StringstrDateTime){SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");Datenow=null,date=null;try{now=df.parse(getDateTime());date=df.parse(strDateTime);}catch(ParseExceptione){e.printStackTrace();}longl=now.getTime()-date.getTime();longday=l/(24*60*60*1000);longhour=(l/(60*60*1000)-day*24);longmin=((l/(60*1000))-day*24*60-hour*60);longs=(l/1000-day*24*60*60-hour*60*60-min*60);System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");returnday;}publicstaticvoidmain(String[]args)throwsException{System.out.println(deltaT("2016-03-1118:02:50"));}}
【本文是清一色专栏作者张勇波的原创文章,转载请通过清一色获取作者授权】
推荐阅读
关于我们| 联系方式| 版权声明| 供稿服务| 友情链接
咕噜网 www.cngulu.com 版权所有,未经书面授权禁止使用
Copyright©2008-2023 By All Rights Reserved 皖ICP备2022009963号-10
联系我们: 39 60 29 14 2@qq.com