android獲取當前秒
① android手機怎樣讓時間顯示精確到秒
只要連著網路就行。
② 在android中如何獲取當前日期
Android中獲取系統時間和日期,星期代碼如下:
import java.text.SimpleDateFormat;
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
Date curDate = new Date(System.currentTimeMillis());//獲取當前時間
String str = formatter.format(curDate);
可以獲取當前的年月時分,也可以分開寫:
復制代碼 代碼如下:
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = sDateFormat.format(new java.util.Date());
如果想獲取當前的年月,則可以這樣寫(只獲取時間或秒種一樣):
Java代碼
復制代碼 代碼如下:
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
String date=sdf.format(new java.util.Date());
當然還有就是可以指定時區的時間(待):
復制代碼 代碼如下:
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);
if(strTimeFormat.equals("24"))
{
Log.i("activity","24");
}
復制代碼 代碼如下:
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)
利用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)
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)
利用Time獲取
復制代碼 代碼如下:
Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone資料。
t.setToNow(); // 取得系統時間。
int year = t.year;
int month = t.month;
int date = t.monthDay;
int hour = t.hour; // 0-23
int minute = t.minute;
int second = t.second;
③ 安卓手機怎麼看現在是幾分幾秒秒從哪看
下載一個Timely,就能看到秒了,Timely要比自帶的時鍾軟體更漂亮更實用,我一直在用。左下角那個可以切換表盤。設置裡面還能更改主題顏色。也是谷歌的軟體。
④ Android 怎麼獲取當前的時間戳
new Date().getTime();
System.currentTimeMillis();
跟java 取時間一樣的
⑤ android獲取手機真實時間與時區,IP地址
手機打開了通過網路同步時間(手機網路同步時間),應該可以直接通過JAVA的類取得時間、時區等地理信息
System.out.println("Current time zone: " + TimeZone.getDefault().getID());
IP地址,可以訪問apnic來分析網頁取真實的IP。
⑥ 安卓手機怎樣讓時間顯示精確到秒
1、首先打開手機主界面,然後選擇點擊「設置」選項,如下圖所示。
⑦ 怎麼把安卓手機時間顯示到秒
要求手機已有root許可權,然後要裝superuser,不同型號手機不同root方式。
1、先打開superuser,退出(這樣做的目的是要保證superuser在後台運行)
2、安裝Xposed框架,打開Xposed外掛模塊,點擊安裝/更新
⑧ android 如何獲取當天23:59的毫秒數
您好:很高興回答你的問題;
主要有以下兩種辦法:
方法一:
Date date=new Date();
String ss= ""+date.getTime();
Calendar c = Calendar.getInstance();
long l = c.getTimeInMillis();
方法二:
Date dt= new Date();
Long time= dt.getTime();
Long time2=System.currentTimeMillis();
這里提供了兩種方式獲取時間,但是如果想獲取前一天的時間,用日歷類實現即可。
我具體寫了一下如何改變日期,希望有用。
public class Test02 {public static void main(String args[]) {Calendar c = Calendar.getInstance();System.out.println("昨天是:"+c.getTime());//System.out.println("今天是:"+c.get(Calendar.YEAR)+"年"+c.get(Calendar.MONTH+1)+"月"+c.get(Calendar.DAY_OF_YEAR)+"日");c.add(Calendar.DAY_OF_YEAR, -1);System.out.println("昨天是:"+c.getTime());//System.out.println("今天是:"+c.get(Calendar.YEAR)+"年"+c.get(Calendar.MONTH+1)+"月"+c.get(Calendar.DAY_OF_YEAR)+"日");long time1 = c.getTimeInMillis();long randtime=(long)(Math.random()*(long)Math.pow(10, 6));long time2 = c.getTimeInMillis()+randtime;System.out.println(time1 + "," + time2);}} 其中long randtime=(long)(Math.random()*(long)Math.pow(10, 6));是隨機產生的一個值,如果你是一天中的時間段,是不是用這個值可以控制時間段的長度,知道開始時間和時間段長度就可以知道結束時間。
肯定行!希望能幫助你,望採納,謝謝!
⑨ android開發 怎麼獲取手機當前時間
Android的文件有建議用Time代替Calendar。用Time對CPU的負荷會較小。在寫Widget時特別重要。
Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone資料。
package itokit.com;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.Time;
import android.widget.TextView;
public class ShowTime extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView myTextView = (TextView)findViewById(R.id.myTextView);
Time time = new Time("GMT+8");
time.setToNow();
int year = time.year;
int month = time.month;
int day = time.monthDay;
int minute = time.minute;
int hour = time.hour;
int sec = time.second;
myTextView.setText("當前時間為:" + year +
"年 " + month +
"月 " + day +
"日 " + hour +
"時 " + minute +
"分 " + sec +
"秒");
}
}