……天天向上

好的想法总是无穷无尽

统计

留言簿(1)

阅读排行榜

评论排行榜

2012年9月10日 #

calendar获取当前日期及时间的用例

  1. import Java.util.*;
  2.   public class ShowDate {
  3.   public static void main(String[] args) {
  4.   Calendar calendar = new GregorianCalendar();
  5.   Date trialTime = new Date();
  6.   calendar.setTime(trialTime);
  7.   // print out a bunch of interesting things
  8.   System.out.println("ERA: " + calendar.get(Calendar.ERA));
  9.   System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
  10.   System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
  11.   System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
  12.   System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
  13.   System.out.println("DATE: " + calendar.get(Calendar.DATE));
  14.   System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
  15.   System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
  16.   System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
  17.   System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
  18.   System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
  19.   System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
  20.   System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
  21.   System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
  22.   System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
  23.   System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
  24.   System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));
  25.   System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));
  26.   System.out.println("Current Time, with hour reset to 3");
  27.   calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
  28.   calendar.set(Calendar.HOUR, 3);
  29.   System.out.println("ERA: " + calendar.get(Calendar.ERA));
  30.   System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
  31.   System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
  32.   System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
  33.   System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
  34.   System.out.println("DATE: " + calendar.get(Calendar.DATE));
  35.   System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
  36.   System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
  37.   System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
  38.   System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));

posted @ 2012-09-19 09:51 japper 阅读(6338) | 评论 (0)编辑 收藏

Android SDK下载和更新失败的解决方法


Android SDK下载和更新失败的解决方法

 

最近刚换了电脑,开始搭建Android开发环境的时候,下载SDK总是会出现如下错误:
 
1.Failed to fetch URL http://dl-ssl.google.com/Android/repository/addons_list-1.xml
据说dl-ssl.google.com在大陆被强了,伟大的天朝真是不让人活了,解决方法就是修改C:\Windows\System32\drivers\etc\hosts文件。添加一行:
 
1.74.125.237.1       dl-ssl.google.com 
这里需要注意的是hosts文件是只读的,我们没有权限修改,需要我们将hosts文件复制到桌面或者其他地方,然后修改,代码如下:
1.# Copyright (c) 1993-2009 Microsoft Corp. 
2.# 
3.# This is a sample HOSTS file used by Microsoft TCP/IP for Windows. 
4.# 
5.# This file contains the mappings of IP addresses to host names. Each 
6.# entry should be kept on an individual line. The IP address should 
7.# be placed in the first column followed by the corresponding host name. 
8.# The IP address and the host name should be separated by at least one 
9.# space. 
10.# 
11.# Additionally, comments (such as these) may be inserted on individual 
12.# lines or following the machine name denoted by a '#' symbol. 
13.# 
14.# For example: 
15.# 
16.#      102.54.94.97     rhino.acme.com          # source server 
17.#       38.25.63.10     x.acme.com              # x client host 
18. 
19.# localhost name resolution is handled within DNS itself. 
20.#   127.0.0.1       localhost 
21.#   ::1             localhost 
22.//亲,就是增加这一句哦  
23.74.125.237.1       dl-ssl.google.com 
然后保存,复制修改后的hosts文件到C:\Windows\System32\drivers\etc 目录,替换文件就好!!!我们再次下载SDK的时候就会成功啦,如下图:
 


嘿嘿,大功告成啦!!!
 
PS:补充下,在mac或Linux中,hosts文件所在位置为/etc/hosts,可以使用sudo vim /etc/hosts来编辑。

posted @ 2012-09-10 11:18 japper 阅读(339) | 评论 (0)编辑 收藏