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

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


    網站導航:
     
    主站蜘蛛池模板: 中文字幕乱码亚洲精品一区| 亚洲av产在线精品亚洲第一站| 日本视频免费高清一本18| 亚洲美女视频一区| 最好免费观看韩国+日本| 免费看一级高潮毛片| 亚洲AV永久无码精品| 国产免费女女脚奴视频网| 特色特黄a毛片高清免费观看| 亚洲国产精品无码av| 午夜一区二区免费视频| 岛国岛国免费V片在线观看| 麻豆狠色伊人亚洲综合网站| 亚洲国产精品一区二区九九| 五月婷婷综合免费| 你懂得的在线观看免费视频| 亚洲一区二区三区国产精华液| 亚洲精品中文字幕乱码三区| 妞干网手机免费视频| 精品免费tv久久久久久久| 亚洲AV无码一区二区乱子仑| 老司机亚洲精品影院| 久久亚洲国产成人精品无码区| 国产免费AV片在线播放唯爱网 | 亚洲AV无码专区在线亚| 中文字幕精品无码亚洲字| 成人免费看吃奶视频网站| 无码人妻AV免费一区二区三区| 日韩国产欧美亚洲v片| 亚洲成人黄色网址| 久久精品九九亚洲精品天堂| 免费人成激情视频| 成人人观看的免费毛片| 在线观看的免费网站无遮挡| 精品免费久久久久国产一区 | 一个人免费观看www视频| 亚洲午夜无码久久久久小说| 亚洲精品视频免费看| 国产AV无码专区亚洲精品| 国产国拍精品亚洲AV片 | 亚洲mv国产精品mv日本mv|