全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
显示图片 | 并排多个listView 2011-03-27获得网络时间 博客分类: androidJNIOSIDEAHTML.net转自:/javadetails/java-0589.htmlWe connect to a publicly accessible time server on the internet and parse the result.List of available time servers :/service/time-servers.htmlNOTE : All users should ensure that their software NEVER queries a server more frequently than once every 4 seconds. Systems that exceed this rate will be refused service. In extreme cases, systems that exceed this limit may be considered as attempting a denial-of-service attack.import java.io.*;import java.text.*;import java.util.*;import .*;public final class DateUtils / NIST, Boulder, Colorado () public static final String ATOMICTIME_SERVER=01:13; / NIST, Gaithersburg, Maryland () / public static final String ATOMICTIME_SERVER=8:13; public final static GregorianCalendar getAtomicTime() throws IOException BufferedReader in = null; try URLConnection conn = new URL(ATOMICTIME_SERVER).openConnection(); in = new BufferedReader (new InputStreamReader(conn.getInputStream(); String atomicTime; while (true) if ( (atomicTime = in.readLine().indexOf(*) -1) break; System.out.println(DEBUG : + atomicTime); String fields = atomicTime.split( ); GregorianCalendar calendar = new GregorianCalendar(); String date = fields1.split(-); calendar.set(Calendar.YEAR, 2000 + Integer.parseInt(date0); calendar.set(Calendar.MONTH, Integer.parseInt(date1)-1); calendar.set(Calendar.DATE, Integer.parseInt(date2); / deals with the timezone and the daylight-saving-time TimeZone tz = TimeZone.getDefault(); int gmt = (tz.getRawOffset() + tz.getDSTSavings() / 3600000; System.out.println(DEBUG : + gmt); String time = fields2.split(:); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time0) + gmt); calendar.set(Calendar.MINUTE, Integer.parseInt(time1); calendar.set(Calendar.SECOND, Integer.parseInt(time2); return calendar; catch (IOException e) throw e; finally if (in != null) in.close(); public static void main(String args) throws IOException SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss); System.out.println(Atomic time : + sdf.format(DateUtils.getAtomicTime().getTime(); /* ref : /doc-tour/atomic_clock.html 49825 95-04-18 22:24:11 50 0 0 50.0 UTC(NIST) * | | | | | | | | | These are the last + | | | | | | | | five digits of the | | | | | | | | Modified Julian Date | | | | | | | | | | | | | | | | Year, Month and Day -+ | | | | | | | | | | | | | | Hour, minute, and second of the -+ | | | | | | current UTC at Greenwich. | | | | | | | | | | | | DST - Daylight Savings Time code -+ | | | | | 00 means standard time(ST), 50 means DST | | | | | 99 to 51 = Now on ST, goto DST when local | | | | | time is 2:00am, and the count is 51. | | | | | 49 to 01 = Now on DST, goto ST when local | | | | | time is 2:00am, and the count is 01. | | | | | | | | | | Leap second flag is set to 1 when -+ | | | | a leap second will be added on the last | | | | day of the current UTC month. A value of | | | | 2 indicates the removal of a leap second. | | | | | | | | Health Flag. The normal value of this -+ | | | flag is 0. Positive values mean there may | | | be an error with the transmitted time. | | | | | | The number of milliseconds ACTS is advancing -+ | | the time stamp, to account for network lag. | | | | Coordinated Universal Time from the National -+ | Institute of Standards & Technology. | | The instant the * appears, is the exact time. -+ */ thanks to
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人员定位检修安全技术措施培训
- 广东省江门市2025-2026学年高一上学期12月份联考化学试卷(解析版)
- 吉林省白城市实验高级中学2024-2025学年高二上学期12月期末考试化学试题(解析版)
- 移动浙江公司宽带装维人员“应知”考试题库及答案
- 2026届临沂市苍山县四年级数学下学期期中联考试题含答案
- 送气服务人员考试题库及答案
- 2026学年青海省西宁市城中区数学三年级第二学期期末模拟试题含答案解析
- 安全生产管理人员安全资格证考试题库(含标准答案)
- 2026年土地估价师《土地估价理论与实务》押题试卷
- 小学六年级美术教案 创意海报设计实践教学
- 2024-2025学年山东省菏泽市高一(下)期末数学试卷(含解析)
- 国企物业薪酬管理办法
- 石料厂安全操作规程
- 低碳烯烃生产技术
- 小学作业公示管理制度
- 幼儿园大班科学公开课《有趣的转动》课件
- 公司客户欠款管理制度
- 文言文对比阅读(《学弈》对比14篇)-2023-2024学年六年级语文下学期
- 2025年华阳集团笔试题库及答案
- 现代产业学院合作协议书范本
- 人工智能安全:原理与实践 课件全套 李剑 第1-16章 人工智能安全概述- 代码漏洞检测原理与实践
评论
0/150
提交评论