- 浏览: 1802027 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
cht的大摩托:
学习
IBM WebSphere Performance Tool / ISA / jca457.jar / ha456.jar / ga439.jar -
leeking888:
有没有linux 64位的相关librfccm.so等包啊?
web test LoadRunner SAP / java / Java Vuser / web_set_max_html_param_len -
paladin1988:
非常不错,多谢了。。
appServer IBM WebSphere / WAS 7 / 8.5 / was commerce -
hzxlb910:
写了这么多
net TCP/IP / TIME_WAIT / tcpip / iperf / cain -
acwyg:
ed2k://|file|LoadRunner.V8.1.is ...
web test performance tools / linux performance tools / windows performance tools
CST和GMT时间的区别
http://www.cnblogs.com/sanshi/archive/2009/08/28/1555717.html
今天遇到一个奇怪的问题,在服务器端通过 Java 获取当前时间为 Fri Aug 28 09:37:46 CST 2009,
转化为GMT时间为:28 Aug 2009 01:37:46 GMT,也就是说GMT时间加上 8 个小时等于CST表示的时间,
那这个CST不就是北京时间么,因为我们是在东八区的。
一切看起来很正常,不过在客户端用JavaScript解析这个时间就有问题了:
1.
// Fri Aug 28 2009 23:37:46 GMT+0800
2.
new
Date(
'Fri Aug 28 09:37:46 CST 2009'
).toString();
好奇怪,这次GMT和CST表示的时间居然相差整整 14 个小时?
百度一下
找到这篇文章
,问题已经很明了。
GMT(Greenwich Mean Time)代表格林尼治标准时间,这个大家都知道。
而CST却同时可以代表如下 4 个不同的时区:
- Central Standard Time (USA) UT-6:00
- Central Standard Time (Australia) UT+9:30
- China Standard Time UT+8:00
- Cuba Standard Time UT-4:00
可见,CST可以同时表示美国,澳大利亚,中国,古巴四个国家的标准时间。
前面提到的通过 Java 获取的CST时间用的是China Standard Time,而客户端JavaScript则默认采用的是美国的中部时间。
所以将 Fri Aug 28 09:37:46 CST 2009 加上 6 个小时,再加上 8 个小时,就等于 Fri Aug 28 2009 23:37:46 GMT+0800
可见,在以后的编程中为了避免错误,还是不要使用CST时间,而尽量采用GMT时间。
http://guoqinhua1986-126-com.iteye.com/blog/231244
********************定时执行任务的三种方法***********
1)java.util.Timer
这个方法应该是最常用的,不过这个方法需要手工启动你的任务:
Timer timer=new Timer();
timer.schedule(new ListByDayTimerTask(),10000,86400000);
这里的ListByDayTimerTask类必须extends TimerTask里面的run()方法。
2)ServletContextListener
这个方法在web容器环境比较方便,这样,在web server启动后就可以
自动运行该任务,不需要手工操作。
将ListByDayListener implements ServletContextListener接口,在
contextInitialized方法中加入启动Timer的代码,在contextDestroyed
方法中加入cancel该Timer的代码;然后在web.xml中,加入listener:
< listener>
< listener-class>com.qq.customer.ListByDayListener< /listener-class>
< /listener>
3)org.springframework.scheduling.timer.ScheduledTimerTask
如果你用spring,那么你不需要写Timer类了,在schedulingContext-timer
.xml中加入下面的内容就可以了:
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
< beans>
< bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
< property name="scheduledTimerTasks">
< list>
< ref local="MyTimeTask1"/>
< /list>
< /property>
< /bean>
< bean id="MyTimeTask" class="com.qq.timer.ListByDayTimerTask"/>
< bean id="MyTimeTask1" class="org.springframework.scheduling.timer.ScheduledTimerTask">
< property name="timerTask">
< ref bean="MyTimeTask"/>
< /property>
< property name="delay">
< value>10000< /value>
< /property>
< property name="period">
< value>86400000< /value>
< /property>
< /bean>
< /beans>
1)java.util.Timer 这个方法应该是最常用的,不过这个方法需要手工启动你的任务: Timer timer=new Timer(); timer.schedule(new ListByDayTimerTask(),10000,86400000); 这里的ListByDayTimerTask类必须extends TimerTask里面的run()方法。
2)ServletContextListener 这个方法在web容器环境比较方便,这样,在web server启动后就可以自动运行该任务,不需要手工操作。将ListByDayListener implements ServletContextListener接口,在 contextInitialized方法中加入启动Timer的代码,在contextDestroyed 方法中加入cancel该Timer的代码;然后在web.xml中,加入listener: < listener> < listener-class>com.qq.customer.ListByDayListener< /listener-class> < /listener> 3)org.springframework.scheduling.timer.ScheduledTimerTask 如果你用spring,那么你不需要写Timer类了,在schedulingContext-timer .xml中加入下面的内容就可以了: < ?xml version="1.0" encoding="UTF-8"?> < !DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> < beans> < bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean"> < property name="scheduledTimerTasks"> < list> < ref local="MyTimeTask1"/> < /list> < /property> < /bean> < bean id="MyTimeTask" class="com.qq.timer.ListByDayTimerTask"/> < bean id="MyTimeTask1" class="org.springframework.scheduling.timer.ScheduledTimerTask"> < property name="timerTask"> < ref bean="MyTimeTask"/> < /property> < property name="delay"> < value>10000< /value> < /property> < property name="period"> < value>86400000< /value> < /property> < /bean> < /beans>
java 字符串<==>时间 格式转换
http://virgos.iteye.com/blog/197894
如:有这样一个字符串:“20070911121547”, 转换成时间格式:2007-09-11 12:15:47
- public class bb {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- SimpleDateFormat df = new SimpleDateFormat( "yyyyMMddhhmmss" );
- String dateString = "20071128175545" ;
- try {
- Date date = df.parse(dateString);
- System.out.println(df.format(date));
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- }
- }
- }
public class bb { public static void main(String[] args) { // TODO Auto-generated method stub SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss"); String dateString = "20071128175545"; try { Date date = df.parse(dateString); System.out.println(df.format(date)); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }
时间无非就是字符串类型转向时间类型,或则时间类型转向字符串类型,还有就是前一个时间,后一个时间的处理等等
自己做了一个例子:
- package com.observe.monitoralarm.util;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- /**
- * 时间帮助类
- * @version $Id: DateUtil.java,v 1.1 2008/05/28 04:29:52 linan Exp $
- * @author LiNan
- */
- public class DateUtil {
- private Calendar calendar=Calendar.getInstance();
- /**
- * 得到当前的时间,时间格式yyyy-MM-dd
- * @return
- */
- public String getCurrentDate(){
- SimpleDateFormat sdf=new SimpleDateFormat( "yyyy-MM-dd" );
- return sdf.format( new Date());
- }
- /**
- * 得到当前的时间,自定义时间格式
- * y 年 M 月 d 日 H 时 m 分 s 秒
- * @param dateFormat 输出显示的时间格式
- * @return
- */
- public String getCurrentDate(String dateFormat){
- SimpleDateFormat sdf=new SimpleDateFormat(dateFormat);
- return sdf.format( new Date());
- }
- /**
- * 日期格式化,默认日期格式yyyy-MM-dd
- * @param date
- * @return
- */
- public String getFormatDate(Date date){
- SimpleDateFormat sdf=new SimpleDateFormat( "yyyy-MM-dd" );
- return sdf.format(date);
- }
- /**
- * 日期格式化,自定义输出日期格式
- * @param date
- * @return
- */
- public String getFormatDate(Date date,String dateFormat){
- SimpleDateFormat sdf=new SimpleDateFormat(dateFormat);
- return sdf.format(date);
- }
- /**
- * 返回当前日期的前一个时间日期,amount为正数 当前时间后的时间 为负数 当前时间前的时间
- * 默认日期格式yyyy-MM-dd
- * @param field 日历字段
- * y 年 M 月 d 日 H 时 m 分 s 秒
- * @param amount 数量
- * @return 一个日期
- */
- public String getPreDate(String field, int amount){
- calendar.setTime(new Date());
- if (field!= null &&!field.equals( "" )){
- if (field.equals( "y" )){
- calendar.add(calendar.YEAR, amount);
- }else if (field.equals( "M" )){
- calendar.add(calendar.MONTH, amount);
- }else if (field.equals( "d" )){
- calendar.add(calendar.DAY_OF_MONTH, amount);
- }else if (field.equals( "H" )){
- calendar.add(calendar.HOUR, amount);
- }
- }else {
- return null ;
- }
- return getFormatDate(calendar.getTime());
- }
- /**
- * 某一个日期的前一个日期
- * @param d,某一个日期
- * @param field 日历字段
- * y 年 M 月 d 日 H 时 m 分 s 秒
- * @param amount 数量
- * @return 一个日期
- */
- public String getPreDate(Date d,String field, int amount){
- calendar.setTime(d);
- if (field!= null &&!field.equals( "" )){
- if (field.equals( "y" )){
- calendar.add(calendar.YEAR, amount);
- }else if (field.equals( "M" )){
- calendar.add(calendar.MONTH, amount);
- }else if (field.equals( "d" )){
- calendar.add(calendar.DAY_OF_MONTH, amount);
- }else if (field.equals( "H" )){
- calendar.add(calendar.HOUR, amount);
- }
- }else {
- return null ;
- }
- return getFormatDate(calendar.getTime());
- }
- /**
- * 某一个时间的前一个时间
- * @param date
- * @return
- * @throws ParseException
- */
- public String getPreDate(String date) throws ParseException{
- Date d=new SimpleDateFormat().parse(date);
- String preD=getPreDate(d,"d" , 1 );
- Date preDate=new SimpleDateFormat().parse(preD);
- SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
- return sdf.format(preDate);
- }
-
}
//-----------------日期-------------------------
Calendar calendar=Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH)+1;
int day=calendar.get(Calendar.DATE);
获取今天的日期字符串
String today=java.text.DateFormat.getDateInstance().format(new java.util.Date());
获取今天的日期
new java.sql.Date(System.currentTimeMillis())
DateFormatStyle.java
package com.javaeye.lindows.util; import java.text.DateFormat; import java.util.Date; public class DateFormatStyle { // 格式化时间: 09-4-8 下午3:57 public String formateTime() { Date nowDate = new Date(); // 获取系统时间样式 Wed Apr 08 15:28:12 CST 2009 System.out.println(nowDate); DateFormat dFormat = DateFormat.getInstance(); String string = dFormat.format(nowDate); return string; } // 格式化时间1:下午04时00分36秒 CST public String formateTime1() { Date nowDate = new Date(); DateFormat dFormat1 = DateFormat.getTimeInstance(DateFormat.FULL); String string1 = dFormat1.format(nowDate); return string1; } // 格式化时间2:下午04时02分15秒 public String formateTime2() { Date nowDate = new Date(); // 获取系统时间 DateFormat dFormat2 = DateFormat.getTimeInstance(DateFormat.LONG); String string2 = dFormat2.format(nowDate); return string2; } // 格式化时间3:下午4:05 public String formateTime3() { Date nowDate = new Date(); // 获取系统时间 DateFormat dFormat3 = DateFormat.getTimeInstance(DateFormat.SHORT); String string3 = dFormat3.format(nowDate); return string3; } // 格式化时间4:2009年4月8日 星期三 public String formateTime4() { Date nowDate = new Date(); // 获取系统时间 DateFormat dFormat4 = DateFormat.getDateInstance(DateFormat.FULL); String string4 = dFormat4.format(nowDate); return string4; } // 格式化时间5:2009年4月8日 public String formateTime5() { Date nowDate = new Date(); // 获取系统时间 DateFormat dFormat5 = DateFormat.getDateInstance(DateFormat.LONG); String string5 = dFormat5.format(nowDate); return string5; } // 格式化时间6:09-4-8 public String formateTime6() { Date nowDate = new Date(); // 获取系统时间 DateFormat dFormat6 = DateFormat.getDateInstance(DateFormat.SHORT); String string6 = dFormat6.format(nowDate); return string6; } public static void main(String[] args) { DateFormatStyle testDate = new DateFormatStyle(); System.out.println("格式化时间: " + testDate.formateTime()); System.out.println("格式化时间1:" + testDate.formateTime1()); System.out.println("格式化时间2:" + testDate.formateTime2()); System.out.println("格式化时间3:" + testDate.formateTime3()); System.out.println("格式化时间4:" + testDate.formateTime4()); System.out.println("格式化时间5:" + testDate.formateTime5()); System.out.println("格式化时间6:" + testDate.formateTime6()); } }
date.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="com.javaeye.lindows.test.DateFormatStyle"%> <head></head> <body> <!-- 时间写法一 --> <jsp:useBean id="DateFormatStyle_id" class="com.javaeye.lindows.test.DateFormatStyle">当前时间是:</jsp:useBean> <%--scriplet 注释--%> <%=DateFormatStyle_id.formateTime2()%> <p>当前时间是: <!-- 时间写法二 --> <% DateFormatStyle dateStyle = new DateFormatStyle(); out.print(dateStyle.formateTime2()); %> </body> </html>
------------------end--------------------
发表评论
-
java Jython / JPython /
2016-12-28 15:19 1195s http://www.jython.org ... -
java coroutine / xiecheng / java Qursar /
2016-12-28 14:52 998s java thread / process / th ... -
JAVA EE Servlet
2011-03-09 03:43 1136Servlet 学习笔记1:Servlet基本结构 ... -
JAVA JDK / JRE / SDK IBM & Oracle
2010-03-09 20:42 3651JAVA JDK Version http://baik ... -
java books
2009-10-26 22:17 1037http://derekop.iteye.com/blog/5 ... -
java http / Cache / Protocol / Client / Session / Cokie / Status / HttpClient
2009-10-22 20:15 4928HttpSesstion / http sessio ... -
JAVA XML / dom / jdom / dom4j / sax / stax / StAX Stream / StAX Event
2009-07-06 01:17 5537http://xml.apache.org/commons ... -
java math
2009-02-16 18:03 1820计数器 (江苏教育考试 ... -
java reflect
2009-02-03 11:42 1433http://www.iteye.com/topic/ ... -
java exception
2009-01-12 10:40 1506http://topic.csdn.net/u/2009010 ... -
java thread / process / thread runnable / thread sleep / thread run
2009-01-10 11:09 2611Java Thread &Memory No ... -
java io / nio / bio / aio
2009-01-09 13:12 2735sdfsafd 未整理 TxtWrite .java ... -
java security / SSL / TLS / md5 / sha / base64 / rsa / des / aes / 3des
2008-11-06 21:40 15512java jdk keytool C:\Pr ... -
java protocol / patent
2008-11-05 01:14 1559专利 ... -
java net unicode / native2ascii / url decode / url encode / UTF8 / js url code
2008-10-28 17:53 16317s http://chengyue2007.ite ... -
java certification SCJP / OCJP / NCRE / RHCE / OCP / ibm certifications
2008-09-26 13:28 2671三级PC上机考试软件下载 http://sk.nee ... -
java Regular Expression / regexp / zhengzebiaodashi
2008-09-26 02:35 2531java Regular Expression / ... -
java lang / BigDecimal
2008-09-24 11:01 1590String StringTest.java ... -
java temp
2008-09-23 18:20 1497asdfdasfadsfdsafsaf --查询商品信息在 ... -
JAVA xml UML
2008-09-21 00:33 1182uml 软件工程组织 http://www.uml.or ...
相关推荐
android time and date java code
public static void main(String[] args) { ... timer.schedule(new MyTask(date),0,1000); } //ps:如有不懂请联系作者!解压后是两个java类,自己创建java项目,把两个类拷贝进去,修改以下包路径即可
java定时器,import java.util.Calendar; import java.util.Date; import java.util.Timer; import java.util.TimerTask; 规定每天几点执行一次
9 9计时器线程Timer 9 10线程联合 9 11守护线程 习题 第10章输入输出流 10 1File类 10 2FileInputStream类 10 3FileOutputStream类 10 4FileReader类和FileWriter类 10 5使用文件对话框打开和保存文件 10 6...
近一直在看线程知识,然后看到Timer定时器使用了线程实现的定时功能,于是了解了解; 本文 从Time类的使用和源码分析两个方面讲解: 1、Time类使用: 1 根据是否循环执行分为两类: 2 3 //只执行一次 4...
//get the date of today Calendar newyears = new GregorianCalendar(2008,Calendar.AUGUST,8); //2008.8.8 long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();//Get difference in ms long...
通过自定义时间段 控制线程的运行时间 i.Date; .Timer;
第1篇 Java编程基础 第1章 Java开发环境的搭建(教学视频:9分钟) 2 1.1 理解Java 2 1.2 搭建Java所需环境 3 1.2.1 下载JDK 3 1.2.2 安装JDK 4 1.2.3 配置环境 5 1.2.4 测试JDK配置...
实例240 定时器(Timer) 458 实例241 数字定时器 459 13.5 线程连接池 462 实例242 手术任务(线程池) 462 实例243 模拟人工服务台(线程连接池) 466 13.6 线程应用实例 471 实例244 下雪的村庄 472 实例245 小...
第1篇 Java编程基础 第1章 Java开发环境的搭建(教学视频:9分钟) 2 1.1 理解Java 2 1.2 搭建Java所需环境 3 1.2.1 下载JDK 3 1.2.2 安装JDK 4 1.2.3 配置环境 5 1.2.4 测试JDK配置是否成功 7...
java.util.Timer 基本方法 schedule 例如: timer.schedule(task, delay,period); //delay为long,period为long:从现在起过delay毫秒以后,每隔period毫秒执行一次。 schedule方法有三个参数 第一个参数就是...
实例240 定时器(Timer) 458 实例241 数字定时器 459 13.5 线程连接池 462 实例242 手术任务(线程池) 462 实例243 模拟人工服务台(线程连接池) 466 13.6 线程应用实例 471 实例244 下雪的村庄 472 实例...
实例240 定时器(Timer) 458 实例241 数字定时器 459 13.5 线程连接池 462 实例242 手术任务(线程池) 462 实例243 模拟人工服务台(线程连接池) 466 13.6 线程应用实例 471 实例244 下雪的村庄 472 实例245 小...
import java.util.Date; import java.util.GregorianCalendar; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import...
Duty 2 Schedule 3======================In chapter 7 of the book section Implementing aspect oriented programming with interceptorson page 255 through page 259 just before the EJB timer service section...
定时器类Timer在java.util包中。使用时,先实例化,然后使用实例的schedule(TimerTask task, long delay)方法,设定指定的任务task在指定的延迟delay后执行。定时器任务类TimerTask是抽象类,继承并重写其run()方法...
计时器计时功能的控制用到了Date类和Timer类,为了让所做的图形界面程序通过事件响应机制实现用户与程序的交互,通过在按钮单击事件里添加一个监控对象,然后使用接口对象的方法来完成相应事件的处理。本程序中还...
{13.8}java.util.Date与java.sql.Date比较}{200}{section.13.8} {13.9}Meta Data}{201}{section.13.9} {13.10}可滚动结果集}{201}{section.13.10} {13.11}Procedure}{201}{section.13.11} {14}xml}{204}{...
JAVA模版引擎Freemarker常用标签(一) 1. if指令 这是一个典型的分支控制指令,该指令的作用完全类似于Java语言中的if,if指令的语法格式如下: <#if condition>... <#elseif condition>... <#elseif condition>......
import java.util.Date ; import java.util.concurrent.TimeUnit ; import com.laurencetrippen.tasksystem4j.Task ; import com.laurencetrippen.tasksystem4j.TaskSystem ; public class Tester { private static...