全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
显示图片 | 并排多个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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 急性扁桃体炎健康宣教总结2026
- 雨课堂学堂在线学堂云《网店客服(江西省井冈山经贸学校)》单元测试考核答案
- 技术服务高品质保证承诺书(6篇)
- 医院门诊流程优化管理规范手册
- 房地产代理业务客户沟通规范指南
- 大数据结论可信承诺书(3篇)
- 网络营销客户服务质量承诺书3篇范文
- 合作项目延期申请商榷函3篇
- 教育信息化建设实施指南及评估手册
- 环境治理实施计划责任书5篇
- 升主动脉、主动脉弓置换术及象鼻支架植入术临床路径(2025更新版)
- 2025年放射工作人员考试题及答案 (含各题型)
- 测绘成果安全保密培训
- 2025年贵州省公务员《行测》真题及答案
- 司机入厂安全教育培训课件
- 四川省医疗服务价格项目汇编(2022版)
- 《物流经济地理》课件(共十二章)-上
- 2025年辽宁卷历史高考试卷(原卷+答案)
- SY4203-2019石油天然气建设工程施工质量验收规范站内工艺管道检验批表格
- 血友病基础知识培训课件
- 辽宁档案初级考试题库及答案
评论
0/150
提交评论