導航:首頁 > 操作系統 > android獲取前一天

android獲取前一天

發布時間:2022-07-12 22:16:23

android中如何計算在當前時間的前一天的時間格式是yyyyMMddHHmmss

Calendar中有個
void add(int field, int amount) 方法 , 其中 field表示你要加減的欄位, cal.add(Calendar.DAY_OF_MONTH,-1);/*得到前一天的值,注意它沒有返回值,執行之後cal的值直接變成了前一天,此方法對閏年、月什麼都有效*/

㈡ 在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;

㈢ android怎麼獲得當前時間

取得系統時間:
1。long time=System.currentTimeMillis();

2。final Calendar mCalendar=Calendar.getInstance();
mCalendar.setTimeInMillis(time);
取得小時:mHour=mCalendar.get(Calendar.HOUR);
取得分鍾:mMinuts=mCalendar.get(Calendar.MINUTE);

3。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

4。DateFormat df = new SimpleDateFormat("HH:mm:ss");
df.format(new Date());

㈣ android calendar怎麼獲取當天的上一天

Calendar c = Calendar.getInstance();
c.setTime(new Date()); //當天
c.add(Calendar.DAY_OF_YEAR, 1); //下一天

㈤ android webview 有沒有獲取歷史記錄集合的方法

有的。mWebView.BackForwardList()這個是集合
mWebView.BackForwardList().getItemAtIndex(position).getUrl();position是int類型。這個是獲取url。
我最近在做安卓瀏覽器,基本不用自帶的,基本都是沒打開一個網頁存在本地資料庫,用起來方便。

㈥ Android 怎麼獲取當前的時間戳

Android獲取當前時間代碼

//需要引用的
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

//詳細代碼
java.util.Date currentdate = new java.util.Date();//當前時間
//long i = (currentdate.getTime()/1000-timestamp)/(60);
//System.out.println(currentdate.getTime());
//System.out.println(i);
Timestamp now = new Timestamp(System.currentTimeMillis());//獲取系統當前時間
System.out.println("now-->"+now);//返回結果精確到毫秒。

時間戳轉日期
int timestamp = 1310457552; //將這個時間戳轉為日期

return getTime(timestamp);

定義getTime, getDate, IntToLong

public static String getTime(int timestamp){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time= null;
try {
String str = sdf.format(new Timestamp(IntToLong(timestamp)));
time = str.substring(11, 16);

String month = str.substring(5, 7);
String day = str.substring(8,10 );
time =getDate(month, day)+ time;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return time;
}

public static String getDate(String month,String day){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小時制
java.util.Date d = new java.util.Date(); ;
String str = sdf.format(d);
String nowmonth = str.substring(5, 7);
String nowday = str.substring(8,10 );
String result = null;

int temp = Integer.parseInt(nowday)-Integer.parseInt(day);
switch (temp) {
case 0:
result="今天";
break;
case 1:
result = "昨天";
break;
case 2:
result = "前天";
break;
default:
StringBuilder sb = new StringBuilder();
sb.append(Integer.parseInt(month)+"月");
sb.append(Integer.parseInt(day)+"日");
result = sb.toString();
break;
}
return result;
}

//java Timestamp構造函數需傳入Long型
public static long IntToLong(int i){
long result = (long)i;
result*=1000;
return result;
}

㈦ android shell 如何獲取明天的日期

date -d "+1 day" +"%Y%m%d"

㈧ 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有獲取當前星期幾的系統方法嗎還是得自己寫一個根據年月日計算星期幾的詳細方法,謝謝

**
* 判斷當前日期是星期幾
*
* @param pTime 設置的需要判斷的時間 //格式如2012-09-08
*
* @return dayForWeek 判斷結果
* @Exception 發生異常
*/
// String pTime = "2012-03-12";
private String getWeek(String pTime) {

String Week = "";

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try {
c.setTime(format.parse(pTime));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (c.get(Calendar.DAY_OF_WEEK) == 1) {
Week += "天";
}
if (c.get(Calendar.DAY_OF_WEEK) == 2) {
Week += "一";
}
if (c.get(Calendar.DAY_OF_WEEK) == 3) {
Week += "二";
}
if (c.get(Calendar.DAY_OF_WEEK) == 4) {
Week += "三";
}
if (c.get(Calendar.DAY_OF_WEEK) == 5) {
Week += "四";
}
if (c.get(Calendar.DAY_OF_WEEK) == 6) {
Week += "五";
}
if (c.get(Calendar.DAY_OF_WEEK) == 7) {
Week += "六";
}

return Week;
}

閱讀全文

與android獲取前一天相關的資料

熱點內容
如何上網上設個人加密賬戶 瀏覽:44
linux打開ssh服務 瀏覽:78
微信位置可以加密嗎 瀏覽:470
演算法蠻力法 瀏覽:438
隨機排練命令 瀏覽:147
python多進程並發 瀏覽:41
安卓軟體安裝如何躲避安全檢測 瀏覽:647
奇幻潮翡翠台源碼百度雲盤 瀏覽:187
什麼軟體可以免費pdf轉word 瀏覽:15
php正則表達式大全 瀏覽:394
androidntp時間 瀏覽:299
輪機長命令簿英文 瀏覽:148
oppo鈴聲設置被加密怎麼處理 瀏覽:548
粵苗app圖形驗證碼怎麼填 瀏覽:899
管家婆架設雲伺服器 瀏覽:254
php的登錄界面代碼 瀏覽:997
php開發客戶端 瀏覽:998
theisle測試服怎麼搜伺服器 瀏覽:447
廣播PDF 瀏覽:218
單片機編程300例匯編百度 瀏覽:35