<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java Source

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
    import java.io.InputStream;
    import java.net.Socket;

    /**
     * 
     * 
    @author ray (justinlei@gmail.com)
     * @date 2009-8-27
     * 
    @version 1.0
     
    */
    public class TimeUtil {
        
    public static final int DEFAULT_PORT = 37;
        
    public static final String DEFAULT_HOST = "time-nw.nist.gov";
        
    private TimeUtil() {
        };

        
    public static long currentTimeMillis(Boolean sync) {
            
    if (sync != null && sync.booleanValue() != true)
                
    return System.currentTimeMillis();
            
    try {
                
    return syncCurrentTime();
            } 
    catch (Exception e) {
                
    return System.currentTimeMillis();
            }
        }

        
    public static long syncCurrentTime()  throws Exception {
            
    // The time protocol sets the epoch at 1900,
            
    // the java Date class at 1970. This number
            
    // converts between them.
            long differenceBetweenEpochs = 2208988800L;

            
    // If you'd rather not use the magic number uncomment
            
    // the following section which calculates it directly.

            
    /*
             * TimeZone gmt = TimeZone.getTimeZone("GMT"); Calendar epoch1900 =
             * Calendar.getInstance(gmt); epoch1900.set(1900, 01, 01, 00, 00, 00);
             * long epoch1900ms = epoch1900.getTime().getTime(); Calendar epoch1970
             * = Calendar.getInstance(gmt); epoch1970.set(1970, 01, 01, 00, 00, 00);
             * long epoch1970ms = epoch1970.getTime().getTime();
             * 
             * long differenceInMS = epoch1970ms - epoch1900ms; long
             * differenceBetweenEpochs = differenceInMS/1000;
             
    */

            InputStream raw 
    = null;
            
    try {
                Socket theSocket 
    = new Socket(DEFAULT_HOST, DEFAULT_PORT);
                raw 
    = theSocket.getInputStream();

                
    long secondsSince1900 = 0;
                
    for (int i = 0; i < 4; i++) {
                    secondsSince1900 
    = (secondsSince1900 << 8| raw.read();
                }
                
    if (raw != null)
                    raw.close();
                
    long secondsSince1970 = secondsSince1900 - differenceBetweenEpochs;
                
    long msSince1970 = secondsSince1970 * 1000;
                
    return msSince1970;
            } 
    catch (Exception e) {
                
    throw new Exception(e);
            }
        }
    }
    posted on 2011-12-04 02:54 JustinLei 閱讀(1645) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲日韩小电影在线观看| 国产美女在线精品免费观看| 免费A级毛片无码久久版| 亚洲国产精品综合久久久| 精品国产免费一区二区三区香蕉 | 香蕉蕉亚亚洲aav综合| 亚洲一区二区三区免费| 亚洲免费在线观看| 一级做性色a爰片久久毛片免费| 亚洲伊人成无码综合网| 国产久爱免费精品视频| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲黄色免费在线观看| 亚洲国产美国国产综合一区二区| 国产精品免费看久久久| 亚洲一区二区三区四区在线观看| 久久国产乱子免费精品| 亚洲韩国在线一卡二卡| 91频在线观看免费大全| 亚洲人成小说网站色| 国产精品美女自在线观看免费 | 亚洲人成网站免费播放| 亚洲欧美不卡高清在线| 亚洲国产成人精品久久久国产成人一区二区三区综 | 午夜影视日本亚洲欧洲精品一区| 拍拍拍无挡免费视频网站| 亚洲综合激情视频| 在线a毛片免费视频观看| 一级毛片在播放免费| 亚洲一区二区三区四区在线观看| 成人五级毛片免费播放| eeuss影院免费直达入口| 亚洲AV无码成人网站久久精品大| 成视频年人黄网站免费视频| 免费福利资源站在线视频| 国产亚洲人成网站观看| 毛片免费在线观看网址| 一级毛片视频免费| 亚洲免费观看网站| 中文字幕人成人乱码亚洲电影 | 日本XXX黄区免费看|