【提要】本篇《java如何給時間格式化》特別爲需要格式編程學習的朋友收集整理的,僅供參考。內容如下:
java中如何格式化的時間,這是一個很簡單的`問題,在實際的編程中經常用,以下是小編爲大家搜索整理的java如何給時間格式化,希望能給大家帶來幫助!更多精彩內容請持續關注我們考試網!
日期格式化
import ;
import leDateFormat;
class dayTime
{
public static void main(String args[])
{
Date nowTime=new Date();
tln(nowTime);
SimpleDateFormat time=new SimpleDateFormat("yyyy MM dd HH mm ss");
tln(at(nowTime));
}
}
public void timerStop(){
if(timer!=null)
el();
}
public static void main(String[] args){
BugXmlTimer myTimer=new BugXmlTimer();
// TODO Auto-generated method stub
rStart();
}
}
//這是執行任務的類,即每隔一段時間要做的事情在這裏
package ;
import rTask;
public class BugXmlTimerTask extends TimerTask {
@Override
public void run() {
t("run task");
}
}
//以下是出發定時操作的類,該類實現了ServletContextListener
public class MyTimerListener implements ServletContextListener {
private BugXmlTimer mytimer = new BugXmlTimer ();
public void contextInitialized(ServletContextEvent event) {
rStart();
}
public void contextDestroyed(ServletContextEvent event) {
rStop();
}
}
然後在裏部署一下,即可在程序啓動後運行定時器了!
merListener