我試了一下沒有錯呀!
創(chuàng)新互聯(lián)建站堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網(wǎng)站建設、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的惠民網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!
我還有一個:
script LANGUAGE="JavaScript"
!--你可以將新年改為其它的節(jié)日--
var urodz= new Date("January 29,2006");
var s="新年";
var now = new Date();
var ile = urodz.getTime() - now.getTime();
var dni = Math.floor(ile / (1000 * 60 * 60 * 24));
if (dni 1)
document.write("今天離"+s+"還有"+dni +"天")
else if (dni == 1)
document.write("只有2天啦!")
else if (dni == 0)
document.write("只有1天啦!")
else
document.write("好象已經(jīng)過了哦!");
/script
import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class TimerDemo extends JFrame implements ActionListener { private static final long serialVersionUID = 201306211111L; private JTextField screen = new JTextField("0"); private JButton start = new JButton("開始"); private JButton reset = new JButton("重置"); private JPanel panel = new JPanel(); private boolean isRunning; private int time; private int timeBetween; public TimerDemo(int timeBetween) { super("計時器"); this.timeBetween = timeBetween; try { init(); } catch (Exception e) { e.printStackTrace(); } } public TimerDemo() { super("計時器"); this.timeBetween = 100; try { init(); } catch (Exception e) { e.printStackTrace(); } } private void init() { panel.setLayout(new GridLayout()); panel.add(start); panel.add(reset); start.addActionListener(this); reset.addActionListener(this); screen.setFont(new Font("幼圓", Font.BOLD, 60)); screen.setHorizontalAlignment(JTextField.CENTER); screen.setEditable(false); Container c = getContentPane(); c.setLayout(new BorderLayout()); c.add(panel, BorderLayout.SOUTH); c.add(screen, BorderLayout.CENTER); this.setSize(200, 150); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setLocationRelativeTo(null); this.setVisible(true); } public static void main(String[] args) { new TimerDemo(1);// 設定 1ms/次 // new TimerDemo(); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == start) { if (start.getText().equals("開始")) { start.setText("暫停"); isRunning = true; } else if (start.getText().equals("暫停")) { start.setText("開始"); isRunning = false; } } if (e.getSource() == reset) { start.setText("開始"); screen.setText("0"); isRunning = false; time = 0; } new Thread(new TimeZone()).start(); } class TimeZone implements Runnable { @Override public void run() { while (isRunning) { time++; if (time = Integer.MAX_VALUE) { screen.setText("ERROR"); JOptionPane.showMessageDialog(null, "ERROR"); isRunning = false; } screen.setText(String.valueOf(time)); try { Thread.sleep(timeBetween); } catch (Exception e) { e.printStackTrace(); } } } }}
import?java.util.Calendar;
import?java.util.Date;
public?class?Countdown2?implements?Runnable?{
public?static?void?main(String[]?args)?{
Thread?cd?=?new?Thread(new?Countdown2());
cd.start();
}
@Override
public?void?run()?{
//?設置日期2012-12-21
Calendar?c?=?Calendar.getInstance();
c.set(2016,?1,?1,?0,?0,?0);
//?單獨設置年、月、日、小時、分鐘、秒
c.set(Calendar.YEAR,?2015);
c.set(Calendar.MONTH,?Calendar.DECEMBER);?//?0?表示1月,11?表示12月
c.set(Calendar.DAY_OF_MONTH,?21);
c.set(Calendar.HOUR_OF_DAY,?0);
c.set(Calendar.MINUTE,?0);
c.set(Calendar.SECOND,?0);
//?獲取2012-12-21?0:0:0時間點對應的毫秒數(shù)
long?endTime?=?c.getTimeInMillis();
//?獲取系統(tǒng)當前時間
Date?now?=?new?Date();
//?獲取當前時間點對應的毫秒數(shù)
long?currentTime?=?now.getTime();
//?計算兩個時間點相差的秒數(shù)
long?seconds?=?(endTime?-?currentTime)?/?1000;
while?(true)?{
long?days?=?seconds?/?(3600?*?24);
long?h?=?seconds?%?(3600?*?24)?/?3600;
long?m?=?seconds?%?(3600?*?24)?%?3600?/?60;
long?s?=?seconds?%?(3600?*?24)?%?3600?%?60;
System.out.println("離2016年元旦還剩:?"?+?days?+?"天"?+?h?+?"小時"?+?m?+?"分"?+?s?+?"秒");
seconds--;
try?{
Thread.sleep(1000);
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
}
}
基于控制臺的話很簡單的,我跟你說一下大體思路吧,二話不說先來個for循環(huán),然后輸出倒計時的數(shù)字,程序睡一秒,在輸出倒計時數(shù)字,如此循環(huán),簡單吧,下面看程序:
public static void main(String[] args) {
for(int i=10;i0;i--){
System.out.print(i+" ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.err.print("爆炸");
}
其他基于網(wǎng)頁的還是基于用戶界面都可以使用這個思路的
當前題目:java年份倒計時代碼,javaweb倒計時
標題鏈接:http://jinyejixie.com/article10/hssgdo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、用戶體驗、移動網(wǎng)站建設、網(wǎng)站制作、搜索引擎優(yōu)化、品牌網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)