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;
Ⅱ android開發,long型時間怎麼取出對應的年月日
long類型的時間說明獲取得到的是時間戳,具體轉換可參考以下代碼
//mill為你龍類型的時間戳
Datedate=newDate(mill);
Stringstrs="";
try{
//yyyy表示年MM表示月dd表示日
//yyyy-MM-dd是日期的格式,比如2015-12-12如果你要得到2015年12月12日就換成yyyy年MM月dd日
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");
//進行格式化
strs=sdf.format(date);
System.out.println(strs);
}catch(Exceptione){
e.printStackTrace();
}
Ⅲ 如何 讓android app 中文顯示年月日
/**
* 獲取當前時間 format:yyyy-MM-dd HH:mm:ss
*/
public static String getCurrentTime(String format) {
SimpleDateFormat df = new SimpleDateFormat(format);
return df.format(new Date());
}
參數format寫成 yyyy年MM月dd日即可 ,HHmmss為時分秒
Ⅳ android 如何獲得當前 年 月 日 還有本周是一年的第幾周以及周幾
date對象就可以
Ⅳ android 的DatePicker怎麼取出 年月日的值
這是一個Android原生的控制項,一個日期控制項,如你所說,有年月日
第一步:
獲取DatePicker的控制項
DatePicker mDatePicker = (DatePicker)findViewById(R.id.datePicker);
第二步:
初始化並設置監聽
mDatePicker.init(mYear,mMonth,mDay,new DatePicker.OnDateChangeListener()
{
@Override
public void onDateChanged(DatePicker view,int year,int monthOfYear,int dayOfMonth)
{
//Todo 對獲取的日期進行處理,例如
Toast.makText(mContext,""+year+monthOfYear+dayOfMonth,1000).show();
}
}
Ⅵ android 獲取當前時間後怎麼獲取年月日
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;
Ⅶ 請問,android中日歷那些年月是怎麼被顯示出來的,是用哪個函數獲取的,謝謝
DateTime
如:
<DateTime x="123" y="123" align="center" alignV="center" size="12" color="#FFFFFFFF" visibility="true" format="@long_date_format"/>
Ⅷ android 怎麼從時間字元串中取出月和日
//
需要解析的日期字元串
String
dateStr
=
"2015-09-27
12:15:31";
//
解析格式,yyyy表示年,MM(大寫M)表示月,dd表示天,HH表示小時24小時制,小寫的話是12小時制
//
mm,小寫,表示分鍾,ss表示秒
SimpleDateFormat
format
=
new
SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
try
{
//
用parse方法,可能會異常,所以要try-catch
Date
date
=
format.parse(dateStr);
//
獲取日期實例
Calendar
calendar
=
Calendar.getInstance();
//
將日歷設置為指定的時間
calendar.setTime(date);
//
獲取年
int
year
=
calendar.get(Calendar.YEAR);
//
這里要注意,月份是從0開始。
int
month
=
calendar.get(Calendar.MONTH);
//
獲取天
int
day
=
calendar.get(Calendar.DAY_OF_MONTH);
}
catch
(ParseException
e)
{
e.printStackTrace();
}
Ⅸ android使用sqlite存儲一個時間,欄位為datetime,怎麼取得年、月、日啊
存儲時間的時候最好存long型,就是date.getTime();的值,然後取出來之後再用Date d = new Date(time);回復就好了,而如果你存儲的時候如果是類似「2014-07-09 12:23:66」這樣的字元串,那個你就需要使用dateFormatter,我習慣用SimpleDateFormatter,然後初始化的時候就用"yyyy-MM-dd hh:mm:ss"來作為格式化字元串,你可以網路下android SimpleDateFormatter