A. java代碼怎樣獲取internet標准時間
獲取internet標准時間,參考以下代碼:
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));//時區設置
URLurl=newURL("
);//取得資源對象
URLConnectionuc=url.openConnection();//生成連接對象
uc.connect();//發出連接
longld=uc.getDate();//取得網站日期時間(時間戳)
Datedate=newDate(ld);//轉換為標准時間對象
//分別取得時間中的小時,分鍾和秒,並輸出
System.out.print(date.getHours()+"時"+date.getMinutes()+"分"+date.getSeconds()+"秒");
B. java 怎麼獲取一個月的日期
/**
*
*獲取指定月份的日歷信息
*
*@paramyear
*年
*@parammonth
*月
*@return
*/
publicstaticint[]getMonthCalendar(intyear,intmonth){
Calendarcl=Calendar.getInstance();
cl.set(year,month,1);
intfirstDay=cl.getMinimum(Calendar.DAY_OF_MONTH);
intlastDay=cl.getMaximum(Calendar.DAY_OF_MONTH);
int[]day=newint[lastDay];
for(inti=0;i<lastDay;i++){
day[i]=i+firstDay;
}
returnday;
}
C. java怎麼獲取gmt當前的系統時間
Date now = new Date(); 當前時間就是now,你試著列印一下就出來了,如果對日期時間格式有要求,就SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//設置日期格式,不就OK了
D. java中獲得日期用timestamp,獲得的是什麼時間
獲得的是自1970年1月1日(08:00:00GMT)至當前時間的總毫秒數,類型為long
E. 怎麼實時同步java虛擬機與操作系統時區 及JVM啟動後再更改操作系統時區或時間也能保持其同步
在一個精簡的Linux安裝上jre,發現所有的java程序獲取的時間都不是系統時間。後來發現原來是時區不對。
java程序獲取的時間都是GMT時間,而系統是北京時間,應該是GMT+8,剛好相差8小時。網上搜了好多資料,只有兩種方法:1、在程序中使用
java的函數設定時區。2、在啟動java程序時加參數-Duser.timezone=GMT+8
F. java中怎麼將日期轉換為GMT格式
其實不管建不建議,能用就行,不非得用推薦的。
String toGMT(Date date) {
try {
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
format.setCalendar(cal);
return format.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
}
G. 用JAVA編android軟體時 需要用到的 關於 獲取 或 處理 時間的 函數有哪些 詳細點
1、Calendar
Calendar c = Calendar.getInstance();
取得系統日期:year = c.get(Calendar.YEAR)
month = c.grt(Calendar.MONTH)
day = c.get(Calendar.DAY_OF_MONTH)
取得系統時間:hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)
2、new Date
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
Date curDate = new Date(System.currentTimeMillis());//獲取當前時間
String str = formatter.format(curDate);
可以指定時區的時間(待):
df=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA);
System.out.println(df.format(new Date()));
如何獲取Android系統時間是24小時制還是12小時制
ContentResolver cv = this.getContentResolver();
String strTimeFormat = android.provider.Settings.System.getString(cv,
android.provider.Settings.System.TIME_12_24);
(strTimeFormat.equals("24"))
{Log.i("activity","24");}
3、new Time 獲取24小時時間
Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone資料。
t.setToNow(); // 取得系統時間。
int year = t.year;
int month = t.month;
date = t.monthDay;
int hour = t.hour; // 0-23
int minute = t.minute;
int second = t.second;
H. java時間格式轉換 Thu Dec 24 17:33:00 GMT+08:00 2015 我想轉
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String str=df.format(date);