當前位置:首頁 » 安卓系統 » android獲取當前星期

android獲取當前星期

發布時間: 2023-10-23 15:07:46

A. 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;
}

B. android 怎麼獲得星期幾

Java代碼如下:
public class DataString {
private static String mYear;
private static String mMonth;
private static String mDay;
private static String mWay;

public static String StringData(){
final Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
mYear = String.valueOf(c.get(Calendar.YEAR)); // 獲取當前年份
mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 獲取當前月份
mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 獲取當前月份的日期號碼
mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
if("1".equals(mWay)){
mWay ="天";
}else if("2".equals(mWay)){
mWay ="一";
}else if("3".equals(mWay)){
mWay ="二";
}else if("4".equals(mWay)){
mWay ="三";
}else if("5".equals(mWay)){
mWay ="四";
}else if("6".equals(mWay)){
mWay ="五";
}else if("7".equals(mWay)){
mWay ="六";
}
return mYear + "年" + mMonth + "月" + mDay+"日"+"/星期"+mWay;
}

}

C. 安卓手機怎麼修改系統時間

您好,手機修改時間的方法如下(以小米手機為例):

1、點擊手機中的「設置」圖標,然後找到「更多設置」

2、點擊設置後找到更多設置,點擊進入後點擊日期和時間

D. Android Calendar.set方法,設置星期幾

應該是2015-1-6

=======
2015-1-10 這個應該是周六,現在變成該周的周三 所以應該是2015-1-6

E. 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;
}

熱點內容
去角質皮面膜怎麼樣配置 發布:2024-11-30 10:44:22 瀏覽:808
證券首次開戶後為什麼沒密碼 發布:2024-11-30 10:41:57 瀏覽:316
玩具廠資料庫 發布:2024-11-30 10:41:57 瀏覽:786
學校考試伺服器地址 發布:2024-11-30 10:35:30 瀏覽:683
nas無盤伺服器搭建教程 發布:2024-11-30 10:27:07 瀏覽:156
觸摸精靈腳本解密 發布:2024-11-30 10:27:04 瀏覽:328
如何解鎖密碼鎖上的密碼用數字解 發布:2024-11-30 10:07:55 瀏覽:454
文件夾選項怎麼找 發布:2024-11-30 10:05:50 瀏覽:378
安卓手機界面下面返回鍵怎麼設置 發布:2024-11-30 09:59:12 瀏覽:65
名ftp是 發布:2024-11-30 09:59:12 瀏覽:294