import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import org.apache.log4j.Logger; public class Time { public static Logger logger=Logger.getLogger(Time.class); public static GregorianCalendar ggcalendar=new GregorianCalendar(Locale.CHINA); /** * * @param datestr * @return yyyy-MM-dd hh:mm:ss * @throws ParseException */ public static Date switchToyMdhms(String datestr) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date nowtime=null; try { if(datestr.trim().length()<11) { datestr=datestr.trim()+" 00:00:00"; } nowtime = df.parse(datestr); nowtime = new java.sql.Timestamp(nowtime.getTime()); } catch (ParseException e) { logger.info(e); } return nowtime; } /** * * @param datestr * @return yyyy-MM-dd * @throws ParseException */ public static Date switchToyMd(String datestr) throws ParseException { Date nowtime=null; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); nowtime = df.parse(datestr); nowtime = new java.sql.Date(nowtime.getTime()); return nowtime; } /** * * @return yyyy-MM-dd * @throws ParseException */ public static Date getsystimeyMd() throws ParseException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date2 = df.format(new Date()); java.util.Date nowtime =null; nowtime= df.parse(date2); nowtime= new java.sql.Date(nowtime.getTime()); return nowtime; } /** * * @return yyyy-MM-dd hh:mm:ss * @throws ParseException */ public static Date getsystimeyMdhms() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date2 = df.format(new Date()); java.util.Date nowtime =null; try { nowtime= df.parse(date2); } catch (ParseException e) { logger.info(e); } nowtime= new java.sql.Timestamp(nowtime.getTime()); return nowtime; } /** * * @return yyyy-MM-dd hh:mm:ss * @throws ParseException */ public static Date getTodayStart() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd 00:00"); String date2 = df.format(new Date()); java.util.Date nowtime =null; try { nowtime= df.parse(date2); } catch (ParseException e) { logger.info(e); } nowtime= new java.sql.Timestamp(nowtime.getTime()); return nowtime; } /** * * @return yyyy-MM-dd hh:mm:ss * @throws ParseException */ public static Date getTodayEnd() throws ParseException { return switchToyMdhms(getsystimeyMd().toString()+" 23:59:59"); } /** * * @param date * @return Stringyyyy-MM-dd */ public static String getFormatYYMMDD(Date date){ if(date==null) return ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(date); } /*** * 将Timestamp类型的数据转换成字符串 * @param date * @return */ public static String getFormatYYYYMMDDHHMMSSS(Timestamp date){ // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//hh:am/pm 中的小时数(1-12) SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//HH:一天中的小时数(0-23) return df.format(date); } public static String getFormatYYMMDD(){ Date date=new Date(); if(date==null) return ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); return sdf.format(date); } /** * 返回当前的年 * @return */ public static Integer year(){ return ggcalendar.get(Calendar.YEAR); } /** * 返回当前月份 * @return */ public static Integer month(){ return ggcalendar.get(Calendar.MONTH)+1; } /** * 返回当前是几号 * @return */ public static Integer date(){ return ggcalendar.get(Calendar.DATE); } public static void main(String[] args) throws ParseException { /* Time.getsystimeyMd(); Time.getsystimeyMdhms(); Time.switchToyMd("2009-12-10"); Time.switchToyMdhms("2008-02-02 13:25:03");*/ System.out.println(Time.year().toString()+Time.month().toString()+Time.date().toString()); Timestamp a=new Timestamp(new Date().getTime()); SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(df1.format(a)); SimpleDateFormat df = new SimpleDateFormat("E MM月dd日"); String date = df.format(a); System.out.println(date); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(a.getTime()); cal.add(Calendar.DATE, 1); System.out.println(df.format(cal.getTime())); cal.add(Calendar.DATE, 1); System.out.println(df.format(cal.getTime())); cal.add(Calendar.DATE, 1); System.out.println(df.format(cal.getTime())); cal.add(Calendar.DATE, 1); System.out.println(df.format(cal.getTime())); cal.add(Calendar.DATE, 1); System.out.println(df.format(cal.getTime())); cal.add(Calendar.DATE, 1); System.out.println(df.format(cal.getTime())); System.out.println((new SimpleDateFormat("E")).format(cal.getTime())); } }
相关推荐
java日期格式化工具类,一些常用的日期操作方法
NULL 博文链接:https://bijian1013.iteye.com/blog/2306763
Eclipse中cvs的使用.pdf Eclipse中Web应用开发基础.pdf HashSet类的用法.pdf Hashtable类的用法.pdf ...日期及其格式化.pdf 数字的格式化.pdf 网页之间共享数据.pdf 异常处理.pdf 在Eclipse中使用Struts开发购物车.pdf
java常用日期工具类方法. 包含格式化日期,字符串转日期格式,日期格式转字符串,获取当天是本月第几天、是当年多少天等
日期操作是日常开发当中最常见的操作之一,故开放下自己封装的常用工具操作方法。 在java中队日期类型的处理并不方便,通常都需要借助java.text.SimpleDateFormat类来实现日期类型 和字符串类型之间的转换,但是在...
2、时区处理:了解如何使用Java日期时间类处理多时区的情况,包括转换、调整时差、比较等操作。 3、计划任务与调度:学习如何使用日期时间类来实现计划任务和调度功能,例如定时执行任务、定期触发事件等。 4、日历...
比较实用的日期工具类,日期格式化,查询日期,日期比较等等。
在Java程序设计过程中,对应日期和时间的格式化,还有一个简单的格式化方式,就是java.text.SimpleDateFormat,该类中用字符串指定日期和时间的格式,字符串中的字符称为模式字符,模式字符区分大小写。常见的模式...
java.util.concurrent 在并发编程中很常用的实用工具类。 java.util.concurrent.atomic 类的小工具包,支持在单个变量上解除锁的线程安全编程。 java.util.concurrent.locks 为锁和等待条件提供一个框架的接口和类...
* 在工具类中经常使用到工具类的格式化描述,这个主要是一个日期的操作类,所以日志格式主要使用 SimpleDateFormat的定义格式. * * 格式的意义如下: 日期和时间模式 * 日期和时间格式由日期和时间模式...
日期格式化、得到n天之后的日期、得到n天之后是周几等
xk-time是时间转换,时间计算,时间格式化,时间解析,日历,时间cron表达和时间NLP等的工具,使用Java8,线程安全,简单易用,多个70多个常用日期格式化模板,支持Java8时间类和日期,轻量级,无第三方依赖。...
java.util.concurrent 在并发编程中很常用的实用工具类。 java.util.concurrent.atomic 类的小工具包,支持在单个变量上解除锁的线程安全编程。 java.util.concurrent.locks 为锁和等待条件提供一个框架的接口和类,...
一、Java基础知识 1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别。 2.字符串的操作: 写一个方法,实现字符串的反转,如:输入abc,输出cba 写一个方法,实现字符串的替换,... 如何格式化日期
java.util.concurrent 在并发编程中很常用的实用工具类。 java.util.concurrent.atomic 类的小工具包,支持在单个变量上解除锁的线程安全编程。 java.util.concurrent.locks 为锁和等待条件提供一个框架的接口和类...
Java日期选择控件完整源代码 14个目标文件 内容索引:JAVA源码,系统相关,日历,日期选择 Java语言开发的简洁实用的日期选择控件,源码文件功能说明: [DateChooser.java] Java 日期选择控件(主体类) [public] ...
Java日期选择控件完整源代码 14个目标文件 内容索引:JAVA源码,系统相关,日历,日期选择 Java语言开发的简洁实用的日期选择控件,源码文件功能说明: [DateChooser.java] Java 日期选择控件(主体类) [public] ...
1. java日期时间工具类,基于 java.util.Calendar。 2. 提供常用静态方法如快速获取年/月/日初始及终末时间,快速加减年/月/日/时/分/秒,日期解析、格式化输出、严格验证日期格式等。 3. 连续操作时推荐实例化。...
这里主要是包含了java中常用的方法类,如日期的格式化,String 类型的处理,分页等
包括条形码操作工具、二维码操作、图片验证码工具、动态密码工具、雪花算法id工具、签名工具、poi导出、json转换、文件操作、分页、日期处理、jdbc、大数运算及格式化、gzip压缩、http 结构说明如下: ...