java怎樣給時(shí)間格式化
【提要】本篇《java如何給時(shí)間格式化》特別為需要格式編程學(xué)習(xí)的朋友收集整理的,僅供參考。內(nèi)容如下:

java中如何格式化的時(shí)間,這是一個(gè)很簡(jiǎn)單的問(wèn)題,在實(shí)際的編程中經(jīng)常用,以下是小編為大家搜索整理的java如何給時(shí)間格式化,希望能給大家?guī)?lái)幫助!更多精彩內(nèi)容請(qǐng)持續(xù)關(guān)注我們考試網(wǎng)!
日期格式化
import java.util.Date;
import java.text.SimpleDateFormat;
class dayTime
{
public static void main(String args[])
{
Date nowTime=new Date();
System.out.println(nowTime);
SimpleDateFormat time=new SimpleDateFormat("yyyy MM dd HH mm ss");
System.out.println(time.format(nowTime));
}
}
public void timerStop(){
if(timer!=null)
timer.cancel();
}
public static void main(String[] args){
BugXmlTimer myTimer=new BugXmlTimer();
/pic/p>
myTimer.timerStart();
}
}
/pic/p>
package com.my.time;
import java.util.TimerTask;
public class BugXmlTimerTask extends TimerTask {
@Override
public void run() {
System.out.print("run task");
}
}
/pic/p>
public class MyTimerListener implements ServletContextListener {
private BugXmlTimer mytimer = new BugXmlTimer ();
public void contextInitialized(ServletContextEvent event) {
mytimer.timerStart();
}
public void contextDestroyed(ServletContextEvent event) {
mytimer.timerStop();
}
}
然后在web.xml里部署一下,即可在程序啟動(dòng)后運(yùn)行定時(shí)器了!
com.my.time.MyTimerListener
【java怎樣給時(shí)間格式化】相關(guān)文章:
java如何給時(shí)間格式化07-31
java格式化輸出的方法10-12
怎樣格式化內(nèi)存卡01-22
怎樣保護(hù)硬盤不被格式化10-07
Java 的日期時(shí)間02-03
php格式化時(shí)間戳的方法技巧01-04
Java獲取UTC時(shí)間的方法03-18
java垃圾回收機(jī)制是怎樣的01-23
在Java中調(diào)用存儲(chǔ)過(guò)程是怎樣的01-26
- 相關(guān)推薦