| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 546 人关注过本帖
标题:关于一道时间的问题
只看楼主 加入收藏
枫xby
Rank: 5Rank: 5
等 级:职业侠客
威 望:8
帖 子:82
专家分:371
注 册:2014-10-19
结帖率:71.43%
收藏
已结贴  问题点数:10 回复次数:4 
关于一道时间的问题
题目是调用System.currentTimeMillis()返回从1970年到一月一号0点开始的毫秒数,要显示几几年 几月几日,几点几分几秒 ,我可以编写几点几分几秒 ,但年数 我感觉有点转不过来了 ,就大神指导一下
2015-03-30 21:22
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:10 
程序代码:
import java.text.SimpleDateFormat;

public class SimpleDateFormatTest {
    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    public static void main(String... args) {
        System.out.print(simpleDateFormat.format(System.currentTimeMillis()));
    }
}


大约就是这么个效果:
2015/03/31 20:36:59
2015-03-31 19:36
枫xby
Rank: 5Rank: 5
等 级:职业侠客
威 望:8
帖 子:82
专家分:371
注 册:2014-10-19
收藏
得分:0 
回复 2楼 日知己所无
你能帮我看看这个
public class Testsum {
      public static void main(String[] args){
      
          long totalMilliseconds = System.currentTimeMillis();
          long totalSeconds = totalMilliseconds/1000;
          long currentSeconds = totalSeconds % 60;
          long totalMinutes = totalSeconds / 60;
          long currentMinutes = totalMinutes % 60;
          long totalHours = totalMinutes / 60;
          long currentHours = totalHours % 24;
          long totalDay = totalHours / 24;
          long totalYears = totalDay/365;
          int currentYears = (int)(totalYears +1970);
          int days = (int)(totalDay%365);
         
          if((currentYears%4==0 && currentYears%100!=0 )|| currentYears%400==0){
               if(days<=30){
                    int days2=days+1;
                    System.out.println("Current date and time is Junuary"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                  
                   else if(days<=59){
                    int days2=days-30;
                    System.out.println("Current date and time is February"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=90){
                    int days2=days-59;
                    System.out.println("Current date and time is March"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                  }
                   else if(days<=120){
                    int days2=days-90;
                    System.out.println("Current date and time is May"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=151){
                    int days2=days-120;
                    System.out.println("Current date and time is April"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                 }
                   else if(days<=181){
                    int days2=days-151;
                    System.out.println("Current date and time is June"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                 
                }
                   else if(days<=212){
                    int days2=days-181;
                          System.out.println("Current date and time is July"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=243){
                    int days2=days-212;
                          System.out.println("Current date and time is August"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=272){
                    int days2=days-242;
                          System.out.println("Current date and time is Sept"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=303){
                    int days2=days-272;
                          System.out.println("Current date and time is October"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=333){
                    int days2=days-303;
                          System.out.println("Current date and time is November"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=353){
                    int days2=days-333;
                          System.out.println("Current date and time is November"+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                  }
                  else{
                   if(days<=30){
                    int days2=days+1;
                    System.out.println("Current date and time is Junuary "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                  
                   else if(days<=58){
                    int days2=days-30;
                    System.out.println("Current date and time is February "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=89){
                    int days2=days-58;
                    System.out.println("Current date and time is March "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                  }
                   else if(days<=119){
                    int days2=days-89;
                    System.out.println("Current date and time is May "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=150){
                    int days2=days-119;
                    System.out.println("Current date and time is April "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                 }
                   else if(days<=180){
                    int days2=days-150;
                    System.out.println("Current date and time is June "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                 
                }
                   else if(days<=211){
                    int days2=days-180;
                          System.out.println("Current date and time is July "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=242){
                    int days2=days-211;
                          System.out.println("Current date and time is August "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=271){
                    int days2=days-241;
                          System.out.println("Current date and time is Sept "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=302){
                    int days2=days-271;
                          System.out.println("Current date and time is October "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=332){
                    int days2=days-302;
                          System.out.println("Current date and time is November "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                   else if(days<=352){
                    int days2=days-332;
                          System.out.println("Current date and time is November "+days2+", "+currentYears+" "+currentHours+":"+currentMinutes+":"+currentSeconds);
                   }
                  }
          }
              
         
         

      
      
      }
2015-04-01 17:07
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:0 
回复 3楼 枫xby
你的思路的大的方向是对的,细节上可能有些地方考虑的不够严谨

非要自己研究一下怎么把时间转换为自己想要的格式,可以参考一下JAVA的源代码
把自己想要的部分简化出来应该就可以了

http://
2015-04-04 20:58
孟超
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2015-4-3
收藏
得分:0 
回复 3楼 枫xby
看着好拽的样子,初学者表示很羡慕
2015-04-04 21:12
快速回复:关于一道时间的问题
数据加载中...
 
   



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

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