android时间戳
❶ android怎么把时间戳转换成小时
你好,很高兴能为你解答问题!
日期和时间中设置。希望对你有帮助,满意请采纳,非常感谢!
❷ 如何将android时间戳转换成时间 android怎么把时间戳转换成小时
mysql数据库的日期字段类型建议为varchar或者char,存入时间戳。 取出的时候,将时间戳转换为你需要的时间格式就好。 例: 假设取出值为$time echo date('Y-m-d H:i:s',$time); 你就会看到:2011-11-23 17:42:43的时间格式
❸ android程序在logcat中不停地打印timeline时间戳
Android开发中,所的有输出都在logcat中 包含System.out输出和printStackTrace()输出都在Logcat中,Android开发,建议使用android提供的Log工具类来打印信息。
找到Logcat视图的方式:
Eclipse,在Window
Show View会出来一个对话框
点击Ok按钮时,会在控制台窗口出现LogCat视窗
android.util.Log常用的方法有以下5个:Log.v()Log.d()Log.i()Log.w()以及Log.e()。根据首字母对应VERBOSE,DEBUG,INFO,WARN,ERROR。
1、Log.v 的调试颜色为黑色的,任何消息都会输出,这里的v代表verbose啰嗦的意思,平时使用就是Log.v("","");
2、Log.d的输出颜色是蓝色的,仅输出debug调试的意思,但他会输出上层的信息,过滤起来可以通过DDMS的Logcat标签来选择.
3、Log.i的输出为绿色,一般提示性的消息information,它不会输出Log.v和Log.d的信息,但会显示i、w和e的信息
4、Log.w的意思为橙色,可以看作为warning警告,一般需要我们注意优化Android代码,同时选择它后还会输出Log.e的信息。
5、Log.e为红色,可以想到error错误,这里仅显示红色的错误信息,这些错误就需要认真的分析,查看栈的信息了。
❹ 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;
}
❺ 安卓移动文件创建时间戳改变
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件。
1.命令格式:
touch [选项]... 文件...
2.命令参数:
-a 或--time=atime或--time=access或--time=use 只更改存取时间。
-c 或--no-create 不建立任何文档。
-d 使用指定的日期时间,而非现在的时间。
-f 此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。
-m 或--time=mtime或--time=modify 只更改变动时间。
-r 把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。
-t 使用指定的日期时间,而非现在的时间。
3.命令功能:
touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间。
4.使用范例:
实例一:创建不存在的文件
命令:
touch log2012.log log2013.log
输出:
[root@localhost test]# touch log2012.log log2013.log
[root@localhost test]# ll
-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log
-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log
如果log2014.log不存在,则不创建文件
[root@localhost test]# touch -c log2014.log
[root@localhost test]# ll
-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log
-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log
实例二:更新log.log的时间和log2012.log时间戳相同
命令:
touch -r log.log log2012.log
输出:
[root@localhost test]# ll
-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log
-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log
-rw-r--r-- 1 root root 0 10-28 14:48 log.log
[root@localhost test]# touch -r log.log log2012.log
[root@localhost test]# ll
-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log
-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log
-rw-r--r-- 1 root root 0 10-28 14:48 log.log
实例三:设定文件的时间戳
命令:
touch -t 201211142234.50 log.log
输出:
[root@localhost test]# ll
-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log
-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log
-rw-r--r-- 1 root root 0 10-28 14:48 log.log
[root@localhost test]# touch -t 201211142234.50 log.log
[root@localhost test]# ll
-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log
-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log
-rw-r--r-- 1 root root 0 2012-11-14 log.log
❻ android 将时间戳转为代表"距现在多久之前"的字符串
publicstaticfinalvoidtestDate(){
//比如现在时间:2016/5/3011:45:5
Datenow=newDate(1464579905000l);
//上次时间:2016/5/2811:44:15
Dateold=newDate(1464407055000l);
System.out.println(String.format("距现在%s之前",testPassedTime(now.getTime(),old.getTime())));
}
privatestaticfinallongMINUTE_SECONDS=60;//1分钟多少秒
privatestaticfinallongHOUR_SECONDS=MINUTE_SECONDS*60;
privatestaticfinallongDAY_SECONDS=HOUR_SECONDS*24;
privatestaticfinallongYEAR_SECONDS=DAY_SECONDS*365;
(longnowMilliseconds,longoldMilliseconds){
longpassed=(nowMilliseconds-oldMilliseconds)/1000;//转为秒
if(passed>YEAR_SECONDS){
returnpassed/YEAR_SECONDS+"年";
}elseif(passed>DAY_SECONDS){
returnpassed/DAY_SECONDS+"天";
}elseif(passed>HOUR_SECONDS){
returnpassed/HOUR_SECONDS+"小时";
}elseif(passed>MINUTE_SECONDS){
returnpassed/MINUTE_SECONDS+"分钟";
}else{
returnpassed+"秒";
}
}
❼ 如何将android时间戳转换成时间
时间戳就是如1377216000000 这种格式我们在mysql数据库中会经常用到把时间转换成时间戳或把时间戳转换成日期格式了,下面我来介绍安卓中时间戳操作转换方法。
一、原理
时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算。好~ 直接进入主题。(下面封装了一个类,有需要的同学可以参考或是直接Copy 就可以用了。)
如: 2013年08月23日 转化后是 1377216000000
二、步骤
1、创建 DateUtilsl类。
代码如下 复制代码
importjava.text.ParseException;
importjava.text.SimpleDateFormat;
importjava.util.Date;
/*
* @author Msquirrel
*/
public class DateUtils {
privateSimpleDateFormat sf = null;
/*获取系统时间 格式为:"yyyy/MM/dd "*/
public static String getCurrentDate() {
Date d = newDate();
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsf.format(d);
}
/*时间戳转换成字符窜*/
public static String getDateToString(long time) {
Date d = newDate(time);
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsf.format(d);
}
/*将字符串转为时间戳*/
public static long getStringToDate(String time) {
sdf = newSimpleDateFormat("yyyy年MM月dd日");
Date date = newDate();
try{
date = sdf.parse(time);
} catch(ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
returndate.getTime();
}
2、在对应使用的地方调用就可以了。
代码如下 复制代码
DateUtils.getCurrentDate(); //获取系统当前时间
DateUtils.getDateToString(时间戳); //时间戳转为时间格式
DateUtils.getStringToDate("时间格式");//时间格式转为时间戳
❽ android studio 时间戳s是string类型的吗
可以存储为String类型,通常时间戳不是String类型,而是long类型
Android Studio获取本地的时间戳通过下面方法:System.currentTimeMillis();
获取服务器的时间戳,通常返回的是一个字符串类型,即String,可以将其转换long类型使用对于方法:Long.parseLong(Strings)
❾ android 系统时间戳是否从格林尼治时间算起
北京时间与英国时间相差多少呢?英国 时间与北京时间相差约7或8小时,如果您 想去英国旅行或者留学就一定要先熟悉一下 北京时间与英国时间的差距,以免因为时间 弄错的关系而错过登机时间或旅游的行程。 北京和英国所在的时区: 英国所在的时区是标准时区即0时区, 而中国标准时间的北京时间取用的是东8区 的区时。 了解北京时间与英国时间:(英国时间 和北京时间相差约7或8小时) 英国在每年3月最后一个星期天到10月 最后一个星期天采用British Summer Time (BST),又称London Time或者"Big Ben"Time,这就是所谓的夏令时,它相当 于是GMT+1:00。