- 浏览: 581730 次
- 性别:
- 来自: 青岛
文章分类
最新评论
-
Mr_胡:
确实是jquery版本问题,用新版本的jquery没用
Eclipse 支持jQuery 自动提示 -
redcoatjk:
那遇到事务怎么办?事务是配置到service上.在Listen ...
Listener中取Spring容器中Bean的实例 -
dqd979231776:
+1我用遇到了这个问题,解决了好长时间
<input type="image"> 和 <img> 用法区别 -
李庆辉:
Listener中取Spring容器中Bean的实例 -
骑驴走天下:
膜拜大神,讲的清楚明白,今天正好遇到这个问题,本想用大神说的第 ...
Listener中取Spring容器中Bean的实例
/** * 时间处理类 */ package org.boss.web; import java.util.Calendar; import java.util.Date; import java.text.ParseException; import java.text.SimpleDateFormat; public class CalendarDemo { private Calendar calendar; private Date date; private SimpleDateFormat simpleFormat; public CalendarDemo() { calendar = Calendar.getInstance(); date = new Date(); calendar.setTime(date); calendar.setFirstDayOfWeek(calendar.MONDAY); } /** * 获取日期的年的值,数字型。 */ public String getYear() { return String.valueOf(calendar.get(calendar.YEAR)); } /** * 获取日期的月的值,数字型。 */ public String getMonth() { java.text.DecimalFormat format=new java.text.DecimalFormat("00"); String month=format.format(calendar.get(calendar.MONTH) + 1); return month; } /** * 获取日期的日的值,数字型。 */ public String getDay() { java.text.DecimalFormat format=new java.text.DecimalFormat("00"); String day=format.format(calendar.get(calendar.DATE)); return day; } /** * 获取日期的星期的值,数字型。 */ public int getWeekOfMonth() { return calendar.get(calendar.WEEK_OF_MONTH); } /** * 获取时间的小时的值,数字型。 */ public String getHour() { java.text.DecimalFormat format=new java.text.DecimalFormat("00"); String hour=format.format(calendar.get(calendar.HOUR_OF_DAY)); return hour; } /** * 获取日期的分钟的值,数字型。 */ public String getMinute() { java.text.DecimalFormat format=new java.text.DecimalFormat("00"); String minute=format.format(calendar.get(calendar.MINUTE)); return minute; } /** * 获取日期的秒钟的值,数字型。 */ public String getSecond() { java.text.DecimalFormat format=new java.text.DecimalFormat("00"); String second=format.format(calendar.get(calendar.SECOND)); return second; } /** * 获取一个星期中的某天.文字型。 * @return */ public String getDayOfWeek(){ int week= calendar.get(calendar.DAY_OF_WEEK); String strweek=null; switch(week){ case 0: strweek="一"; break; case 1: strweek="二"; break; case 2: strweek="三"; break; case 3: strweek="四"; break; case 4: strweek="五"; break; case 5: strweek="六"; break; case 6: strweek="日"; break; default: } return strweek; } public String getDate() {//将时间转成字符型 return String.valueOf(this.getYear()) + "-" + String.valueOf(this.getMonth()) + "-" + String.valueOf(this.getDay()) + " " + String.valueOf(this.getHour()) + ":" + String.valueOf(this.getMinute()) + ":" + String.valueOf(this.getSecond()); } public Date stringToDate(String strDate){//将字符转成时间 try{ simpleFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//日期的字符强制转换 date=simpleFormat.parse(strDate); return date; }catch(ParseException e){ e.printStackTrace(); } return null; } public String getSampleDate(){//得到简介时间 return String.valueOf(this.getYear()) + "-" + String.valueOf(this.getMonth()) + "-" + String.valueOf(this.getDay()); } public Date sampleStringToDate(String strDate){//将简介时间字符串转成时间 try{ simpleFormat=new SimpleDateFormat("yyyy-MM-dd");//日期的字符强制转换 date=simpleFormat.parse(strDate); return date; }catch(ParseException e){ e.printStackTrace(); } return null; } public String getEndTime(int month){//得到结束时间(按月计算) int nowyear=Integer.parseInt(this.getYear()); int nowmonth=Integer.parseInt(this.getMonth()); int endmonth=nowmonth+month; if(endmonth>12){ endmonth=endmonth-12; nowyear+=1; } String nowDate=String.valueOf(nowyear) + "-" + String.valueOf(endmonth) + "-" + String.valueOf(this.getDay()) + " " + String.valueOf(this.getHour()) + ":" + String.valueOf(this.getMinute()) + ":" + String.valueOf(this.getSecond()); return nowDate; } public int getNumberOfDays(String startTime,String endTime){//比较两个String 时间的相差天数 Date startDate=this.stringToDate(startTime); long longStartTime=startDate.getTime();//得到时间的毫秒 Date endDate=this.stringToDate(endTime); long longEndTime=endDate.getTime();//得到时间的毫秒 int day=(int)((longStartTime-longEndTime)/ 86400000);//得到相差的天数。 return day; } }
发表评论
-
More than one fragment with the name [spring_web] was found.
2019-04-19 13:38 3616项目跑的好好的。突然之间报错,不能tomcat启动。 报 ... -
Linux(CentOS7)tomcat8启动报错
2018-04-26 08:57 1162服务器:Centos7 ,Tomcat8 ,JDK8 项目 ... -
java中Double数值的计算。
2011-12-21 17:31 22682double的计算不精确,会有类似0.000000000 ... -
java中连接池的原理,既常用的连接池有哪几种?
2011-05-16 08:46 3122java中数据库的连接是一个非常耗资源的动作,频繁的建立 ... -
Statement 和PreparedStatement的区别
2011-05-16 08:43 13841. Statement用于处理静态 SQL 语句, P ... -
java中的接口是什么?面向接口编程的好处?
2011-05-16 08:40 2042Java中的接口是一系列方法的声明,是一些方法特征的集 ... -
PrintWriter 类中println和write方法的区别
2011-05-10 08:32 2074问题:编写Socket聊天软件,使用PrintWriter类取 ... -
java class文件反编译---jad、jadclipse
2011-05-05 17:50 2537eclipse的java的class文件的反编译工具:jad ... -
Access restriction: The type SwingUtilities2 is not accessible due to restricti
2011-03-16 09:20 2193报错:Access restriction: The type ... -
java线程的sleep(),wait(),notify(),yield()方法的区别要点
2011-03-03 16:38 19211.sleep()使线程休眠一段时间,一段时间结束后,线程 ... -
java中的栈内存和堆内存
2010-12-15 17:37 1205Java把内存分成两种 ... -
Java泛型再学习
2010-09-30 15:20 1232泛型引入java语言已经有很长一段时间了,在JDK5出来的 ... -
读写properties 文件
2010-01-21 17:08 2375/** * 通用IO类。读取,写入properties文件 ... -
该文件不具有良好格式:DOCTYPE-ExternalID的名称既是SYSTEM又是PUBLIC!
2009-08-12 11:50 2595<?xml version="1.0" ... -
dom4j操作XML
2009-08-11 23:43 2309虽然DOM4J 代表了完全独立的开发结果,但最初,它是JD ... -
网站单例登录
2009-04-07 13:31 1968实现网站的单例登录: 1, 在用户表里增加一个判断登 ... -
log4j.log4j.properties大全
2009-03-19 06:59 1401log4j.rootLogger=DEBUG,CONSOLE, ... -
JSP指令元素简介
2009-01-14 16:30 1461指令元素(Directives ... -
java MD5 加密
2008-08-23 17:30 2040/** * java.security包中的MessageD ... -
自动得到汉语拼音
2008-08-23 17:27 1398import java.util.Iterator; impo ...
相关推荐
提供友好的时间处理接口,方便处理java时间相关问题
本源码资源提供了Java中的日期时间处理类相关内容,包括日期、时间和时区的操作方法和示例。它涵盖了Java编程中常用的日期时间处理需求以及如何使用日期时间类来解决这些问题。 适用人群 本源码资源适用于具备一定...
日期时间的处理类date,time ,datetime
提供各种时间操作,格式化时间格式,时间格式的转换.
主要是把时间处理相关内容总结到一起 封装成类 可以直接进行调用!使用与php代码网站!!!
对年月日进行处理,计算延迟一段时间后的日期问题。 在订购类业务中,频繁涉及时间计算问题。 两个构造函数 public Kdate(int days) public Kdate(int year, int month, int day) 三个公共接口: public Kdate ...
本文实例讲述了PHP时间处理类操作。分享给大家供大家参考,具体如下: php中的几个时间处理类:DateTime,DateTimeZone,DateInterval,DatePeriod。 DateTime :时间类 DateTimeZone:时区内 DateInterval:表示...
date4j是一个用于简化日期和时间操作的Java工具。可以替换java.util.Date。
快速处理时间格式,拥有丰富的时间处理格式
NULL 博文链接:https://baobeituping.iteye.com/blog/801399
时间的处理各种方式 java8 技术 对时间处理的各种方式
没事写了一个关于java时间处理的工具类,很简单
针对时间日期各种格式之间转换等操作的公用类。
这是一个比较全面的处理日期时间的工具类,利用该工具类可以得到你想要的日期时间。里面代码简洁,方法已经封装好,只需要调用即可。自己可以将其打成jar包来用
(DateUtil.java)时间处理类 (RandomUtil.java)随机函数处理类 (OperationUtil.java)Collection工具包类(CollectionUtil.java)等等,如果下载者觉得使用方面的话,在下十分感谢,申明:代码没有经过十分严格...
关于时间的处理类,对日期格式的处理、计算日期的差值,还有长时间格式
为了提高网站的开发速度,可以把主代码封装在一个单独的函数里面,在需要的时候直接调用,下面看看给大家总结的一些时间处理类。大家需要的时候直接调用就可以了。 var myDate = new Date(); myDate.getYear(); //...
一个关于时间处理的工具类,封装了常见的处理时间的方法。一个关于时间处理的工具类,封装了常见的处理时间的方法。一个关于时间处理的工具类,封装了常见的处理时间的方法。
本工具包主要是基于JAVA的底层时间类的处理周期时间的工具包,主要用于处理并得到周期性提醒的时间,比如说您想要在每天8:10、每月1号8:20、每周三8:30、每10分钟、每3小时、每季度第一个月1号8:10等等处理一项...