<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)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲免费综合色在线视频| 免费无码作爱视频| 亚洲最大的成人网| 777成影片免费观看| 亚洲Av无码精品色午夜| 中文在线免费看视频| 91情侣在线精品国产免费| 久久精品国产亚洲av麻豆色欲| 免费国产成人18在线观看| 亚洲AV永久无码精品水牛影视| 成人无码视频97免费| 亚洲精品国产精品乱码视色| 亚洲一区二区三区免费观看| 黄网站色视频免费观看45分钟| 免费一级毛片免费播放| 新最免费影视大全在线播放| 日韩精品免费一级视频| 亚洲嫩草影院在线观看| 人妻18毛片a级毛片免费看| 国产日产亚洲系列| 在线观看免费视频网站色| 亚洲天堂男人天堂| 国产精品一区二区三区免费| 国产亚洲av片在线观看16女人| 久久久久国色av免费看| 亚洲av无码电影网| 国产真实伦在线视频免费观看| 亚洲午夜电影在线观看高清 | 亚洲午夜无码毛片av久久京东热| 久久精品网站免费观看| 亚洲日韩国产一区二区三区在线| 国产一区二区三区在线免费观看 | 久久久久久亚洲精品不卡| 亚洲午夜无码久久久久小说 | XXX2高清在线观看免费视频| 久久这里只有精品国产免费10| 亚洲国产精品无码久久久秋霞1| 亚洲熟伦熟女新五十路熟妇| 99爱在线精品视频免费观看9| 亚洲欧美第一成人网站7777| 永久亚洲成a人片777777|