android获取当前星期
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;
}