| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3276 人关注过本帖
标题:计算世界末日倒数日
取消只看楼主 加入收藏
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
结帖率:90.32%
收藏
 问题点数:0 回复次数:3 
计算世界末日倒数日
看了电影《2012》,编写一个程序计算现在距离世界末日还有多少天

import java.util.*;

public class Date2010 {
    public static void main(String[] args) {
        GregorianCalendar g = new GregorianCalendar();
/*        int year = (int)g.get(Calendar.YEAR);
        int month = (int)g.get(Calendar.MONTH)+1;
        int date = (int)g.get(Calendar.DATE);
        System.out.println("Today is " + year + "-" + month + "-" + date);
*/        
        GregorianCalendar f = new GregorianCalendar(2012, Calendar.DECEMBER, 21);
        
        long dMillis = f.getTimeInMillis() - g.getTimeInMillis();
        long dDay = dMillis/(24*60*60*1000);
        
        System.out.println("今天距离2012年12月21日还有"+dDay+"日");
    }
}
搜索更多相关主题的帖子: 世界 末日 
2010-03-03 10:27
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
收藏
得分:0 
以下是引用xjwxj526在2010-3-3 11:12:32的发言:

有没有界面化啊
import java.util.*;
import java.awt.*;
import javax.swing.*;


public class Date2010 extends JFrame{
   
    private JLabel lbl;
    private GregorianCalendar g;
    private GregorianCalendar f;
    private long dMillis;
    private long dDay;
   
    public Date2010() {
        this.setLayout(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(200, 200, 650, 100);
        lbl = new JLabel();
        lbl.setBounds(0,0,650,100);
        lbl.setFont(new Font(null, Font.BOLD, 30));
        lbl.setForeground(Color.red);

        g = new GregorianCalendar();  
        f = new GregorianCalendar(2012, Calendar.DECEMBER, 21);   
        dMillis = f.getTimeInMillis() - g.getTimeInMillis();
        dDay = dMillis/(24*60*60*1000);

        lbl.setText("今天距离2012年12月21日还有"+dDay+"日");
        this.add(lbl);
        this.setTitle("2012");
        this.setVisible(true);

    }
   
    public static void main(String[] args) {
        Date2010 date2010 = new Date2010();
    }
}

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2010-03-03 12:42
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
收藏
得分:0 
以下是引用心无旁骛在2010-3-7 00:08:17的发言:

时分秒计时呢
import java.util.*;
import java.awt.*;
import javax.swing.*;


public class Date2010_1 extends JFrame implements Runnable{
   
    private JLabel lbl;
    private GregorianCalendar g;
    private GregorianCalendar f;
    private long dMillis;
    private long dDay;
    private long dHour;
    private long dMin;
    private long dSec;
   
    public Date2010_1() {
        this.setLayout(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(200, 200, 800, 100);
        lbl = new JLabel();
        lbl.setBounds(0,0,800,100);
        lbl.setFont(new Font(null, Font.BOLD, 30));
        lbl.setForeground(Color.red);

        this.add(lbl);
        this.setTitle("2012");
        this.setVisible(true);

    }
   
  public void run() {
      while(true) {
          try {
          g = new GregorianCalendar();  
        f = new GregorianCalendar(2012, Calendar.DECEMBER, 21,0,0,0);   
        dMillis = f.getTimeInMillis() - g.getTimeInMillis();
        dDay = dMillis/(24*60*60*1000);
        dHour = 24 - g.get(Calendar.HOUR_OF_DAY);
        dMin = 60 - g.get(Calendar.MINUTE) ;
        dSec = 60 - g.get(Calendar.SECOND) ;
        String str = "今天距离2012年12月21日还有"+dDay+"日" + dHour + "小时" +dMin +"分钟" + dSec + "秒";
        lbl.setText(str);
   
        Thread.sleep(1000);
        } catch (Exception ex) {
        }

      }
  }
   
    public static void main(String[] args) {
        Date2010_1 date2010 = new Date2010_1();
        Thread th = new Thread(date2010);
        th.start();
    }
}

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2010-03-08 09:01
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
收藏
得分:0 
以下是引用谁与争疯在2010-3-9 03:12:02的发言:

你写一个你什么时候去见佛主的嘛。
佛在我心中,时时到见到佛主

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2010-03-09 08:13
快速回复:计算世界末日倒数日
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011573 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved