2015年9月22日 星期二

Android-取得裝置時間 Get Device Date



public void String getStringData(){  
    final Calendar c = Calendar.getInstance();  
    c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
    String mYear = String.valueOf(c.get(Calendar.YEAR));
    String mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);  
    String mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH)); 
    String mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));  
    if("1".equals(mWay)){  
        mWay ="Sun";
    }else if("2".equals(mWay)){  
        mWay ="Mon";
    }else if("3".equals(mWay)){  
        mWay ="Tue";
    }else if("4".equals(mWay)){  
        mWay ="Wed";
    }else if("5".equals(mWay)){  
        mWay ="Thu";
    }else if("6".equals(mWay)){  
        mWay ="Fri";
    }else if("7".equals(mWay)){  
        mWay ="Sat";
    } 
    return mYear + "/"+mMonth + "/" + mDay + "/"  + mWay;
}

歡迎轉載,請註明出處。

沒有留言:

張貼留言