Locale locale=Locale.CHINA; //这是获得本bai地中国时du区
String pattern = "yyyy-MM-dd kk:mm:ss zZ";//这是日期格式
SimpleDateFormat df = new SimpleDateFormat(pattern,locale);//设定日期格式
Date date = new java.util.Date();
//URL url=new URL("http://www.bjtime.cn");//取得资源对象(这个网址经常失败)
URL url=new URL("https://www.taobao.com");//取得资源对象
URLConnection uc=url.openConnection();//生成连接对象
uc.connect(); //发出连接
long ld=uc.getDate(); //取得网站日期时间
date=new Date(ld); //转换为标准时间对象
String bjTime = df.format(date);
System.err.println("北京时间:"+bjTime);
还没有评论,来说两句吧...