㈠ 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;
}