android版本时间戳|Android 怎么获取当前的时间戳

|

1. 如何将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 blocke.printStackTrace();}returndate.getTime();}2、在对应使用的地方调用就可以了。代码如下复制代码DateUtils.getCurrentDate(); //获取系统当前时间DateUtils.getDateToString(时间戳); //时间戳转为时间格式DateUtils.getStringToDate("时间格式");//时间格式转为时间戳

2. Android 系统各版本的推出年份是多少(如Android1.0 1.5 2.1 2.2)

系统版本Android 1.1android手机发布时间:发布于 2009 年 2 月 代表手机:T-MOBILE G1Android 1.5 Cupcake发布于 2009 年 5 月 代表手机:摩托罗拉CILQAndroid 1.6 Donut2009 年 9 月发布 代表手机:索尼爱立信 X10,摩托罗拉A1680Android 2.0 Eclair2009 年 10 月 26 日 代表机型:摩托罗拉XT800,摩托罗拉里程碑Android 2.1 EclairAndroid 2.1: 2009 年 10 月 26 日,又一个主要版本升级以创纪录的速度放出。这次,大版本升级到了Android 2.1 “Eclair.” Android 2.1主要特性: 提升硬件速度 更多屏幕以及分辨率选择 大幅度的用户界面改良 支持 Exchange活动墙纸 大幅改进虚拟键盘 蓝牙 2.1 Google 地图 Android 2.0.1 SDK 于 2009 年 12 月 3 日 发布,之后是2010 年 1 月 10 日的 2.1 版本。很多用户和围观群众可能会奇怪:“为什么 Android 会用甜点作为它们系统版本的代号?”,这个命名方法开始于 Andoird 1.5 发布的时候。作为每个版本代表的甜点的尺寸越变越大,然后按照字母数序:小蛋糕,甜甜圈还有松饼。之前人们预计 2.2 版本的代号会是“馅饼”,但这个被最终证明是错误的,“FroYo”(冻酸奶)才是 Android 2.2 这个伴随 Google Nexus One 发布的新版的最新代号。Android 2.2 Froyo谷歌于北京时间2010年5月20日晚上10:30点在旧金山Moscone会展中心举办Google I/O 2010大会第二天的会议,Google正式发布了代号是“froyo 冻酸奶”的Android操作系统2.2版。 相对于上一版本的 改变: 1、整体性能大幅度的提升 2、3G网络共享功能。 3、Flash的支持。 4、App2sd功能。 5、全新的软件商店。 6、更多的Web应用API接口的开发。Android 2.3 Gingerbreadgingerdroid北京时间2010年12月7日凌晨,Google正式对外发布了他们的下一代智能手机操作系统Android 2.3也就被大家所熟知的Android Gingerbread系统。 主要更新包括: 游戏:增加了新的垃圾回收和优化处理事件,以提高对游戏的支持能力。原生代码可直接存取输入和感应器事件、EGL/OpenGL ES、OpenSL ES。新的管理窗口和生命周期的框架。 多媒体:支持VP8和WebM视频格式,提供AAC和AMR宽频编码,提供了新的音频效果器,比如混响、均衡、虚拟耳机和低频提升 通讯方式:支持前置摄像头、SIP/VOIP和NFC(近场通讯) 站在用户的角度看,这次更新的亮点主要有: 简化界面、速度提升: 更快更直观的文字输入: 一键文字选择和复制/粘帖: 改进的电源管理系统: 新的应用管理方式: 原生支持前置前置摄像头、互联网通话和NFC(近场通讯): 系统原生支持VoIP,可以在联系人里加入它的SIP帐户,然后直接通过系统来拨打VoIP电话。 增加下载管理器:Android 2.4 Gingerbread就像Android 2.0和2.1版本都使用Eclair(法式奶油夹心甜点)一样,Android 2.3和2.4将会共享Gingerbread(姜饼)代号。这两个版本之间的变化不会太大,但是会有不少功能更新。 目前已知的Android 2.4带来的更新包括更多的动画特效、更快的运行速度、软件通话降噪、视频聊天等。 Android 2.4系统不会是之前一直谣传的Android 3.0,其真正的版本号将会是Android 2.4。Android 3.0 Honeycomb2011年2月3日凌晨,谷歌正式发布了专用于平板电脑的Android 3.0 Honeycomb系统。这是首个基于Android的平板电脑专用操作。首款采用Android3.0系统的是MOTO XOOM 。该机是摩托罗拉移动在2011年1月5日,在美国拉斯维加斯 CES电子消费展推出的旗下首款平板电脑。 3.0系统特性 ·专用于平板电脑 ·全新设计的UI增强网页浏览功能 ·n-app purchases功能 ·经过优化的Gmail电子邮箱; ·全面支持Google Maps

3. android怎么把时间戳转换成小时

mysql数据库的日期字段类型建议为varchar或者char,存入时间戳。取出的时候,将时间戳转换为你需要的时间格式就好。例:假设取出值为$timeechodate('y-m-dh:i:s',$time);你就会看到:2011-11-2317:42:43的时间格式

4. 如何用Android写一个时间戳编码程序‘

这是我项目中正在用的时间戳,没经过整理,你看下

package com.tianwei.utils;

import android.net.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

/**

* Created by GT on 2017/8/22.

* 注:Uinix和Windows时间不同

*/

public class Time {

public void Time() {

}

//格式时间

public static String systemTime(String time) {

SimpleDateFormat sDateFormat = null;

if (time != null && time.length() > 0) {

sDateFormat = new SimpleDateFormat(time);

} else {

sDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

}

String date = sDateFormat.format(new java.util.Date());

return date;

}

//无格式时间

public static String systemTime() {

SimpleDateFormat sDateFormat = null;

sDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

String date = sDateFormat.format(new java.util.Date());

return date;

}

/*

* 将时间戳转换为时间

*/

public static String stampToDate(String s, String time) {

String res;

SimpleDateFormat simpleDateFormat;

if (time == null && time.length() > 0) {

simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

} else {

simpleDateFormat = new SimpleDateFormat(time);

}

long lt = new Long(s);

Date date = new Date(lt);

res = simpleDateFormat.format(date);

return res;

}

/*

* 将时间转换为时间戳

*/

public static String dateToStamp(String s) throws ParseException {

String res;

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = null;

try {

date = simpleDateFormat.parse(s);

} catch (java.text.ParseException e) {

e.printStackTrace();

}

long ts = date.getTime();

res = String.valueOf(ts);

return res;

}

/**

* 系统时间戳

*/

public static long dataStampDate() {

long s = System.currentTimeMillis();

// long s = new Date().getTime();

// long s = Calendar.getInstance().getTimeInMillis();

return s;

}

/**

* Unix

* 时间戳转换成日期格式

*

* @param timestampString

* @param formats

* @return

*/

public static String timeStampUnixDate(String timestampString, String formats) {

Long timestamp = Long.parseLong(timestampString) * 1000;

String date = new java.text.SimpleDateFormat(formats).format(new java.util.Date(timestamp));

return date;

}

/**

* Unix

* 日期格式字符串转换成时间戳

*

* @param dateStr 字符串日期

* @param format 如:yyyy-MM-dd HH:mm:ss

* @return

*/

public static String dateUinxTimeStamp(String dateStr, String format) {

try {

SimpleDateFormat sdf = null;

if (format != null && format.length() > 0) {

sdf = new SimpleDateFormat(format);

} else {

sdf = new SimpleDateFormat("yyyyMMddhhmmss");

}

return String.valueOf(sdf.parse(dateStr).getTime() / 1000);

} catch (Exception e) {

e.printStackTrace();

}

return "";

}

/**

* 两个时间间的时间戳计算函数

*

* @param beginDate

* @param endDate

* @param f 时间差的形式0:秒,1:分种,2:小时,3:天

* @return long 秒

*/

public static long getDifference(Date beginDate, Date endDate, int f) {

long result = 0;

if (beginDate == null || endDate == null) {

return 0;

}

try {

// 日期相减获取日期差X(单位:毫秒)

long millisecond = endDate.getTime() – beginDate.getTime();

/**

* Math.abs((int)(millisecond/1000)); 绝对值 1秒 = 1000毫秒

* millisecond/1000 –> 秒 millisecond/1000*60 – > 分钟

* millisecond/(1000*60*60) — > 小时 millisecond/(1000*60*60*24) –>

* 天

* */

switch (f) {

case 0: // second

return (millisecond / 1000);

case 1: // minute

return (millisecond / (1000 * 60));

case 2: // hour

return (millisecond / (1000 * 60 * 60));

case 3: // day

return (millisecond / (1000 * 60 * 60 * 24));

}

} catch (Exception e) {

e.printStackTrace();

}

return result;

}

/**

* 计算时间差

*

* @param starTime 开始时间

* @param endTime 结束时间

* @return 返回时间差

* @param返回类型==1—-天,时,分。 ==2—-时

*/

public String getTimeDifference(String starTime, String endTime) {

String timeString = "";

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

try {

Date parse = dateFormat.parse(starTime);

Date parse1 = dateFormat.parse(endTime);

long diff = parse1.getTime() – parse.getTime();

long day = diff / (24 * 60 * 60 * 1000);

long hour = (diff / (60 * 60 * 1000) – day * 24);

long min = ((diff / (60 * 1000)) – day * 24 * 60 – hour * 60);

long s = (diff / 1000 – day * 24 * 60 * 60 – hour * 60 * 60 – min * 60);

long ms = (diff – day * 24 * 60 * 60 * 1000 – hour * 60 * 60 * 1000

– min * 60 * 1000 – s * 1000);

// System.out.println(day + "天" + hour + "小时" + min + "分" + s +

// "秒");

long hour1 = diff / (60 * 60 * 1000);

String hourString = hour1 + "";

long min1 = ((diff / (60 * 1000)) – hour1 * 60);

timeString = hour1 + "小时" + min1 + "分";

// System.out.println(day + "天" + hour + "小时" + min + "分" + s +

// "秒");

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (java.text.ParseException e) {

e.printStackTrace();

}

return timeString;

}

/**

* Java YEAR、MONTH、DAY_OF_MONTH、HOUR加减法,int num +(日期前) -(日期后)

*

* @param num

* @param type

* @return

*/

public static String timeDateCompute(int num, int type) {

// YEAR、MONTH、DAY_OF_MONTH、HOUR 等

Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。

if (type > 6) {

return null;

}

switch (type) {

case 0://年

cal.add(Calendar.YEAR, -num);

break;

case 1://月

cal.add(Calendar.MONTH, -num);

break;

case 2://日

cal.add(Calendar.DAY_OF_MONTH, -num);//取当前日期的前num天.

break;

case 3://时

cal.add(Calendar.HOUR_OF_DAY, -num);

break;

case 4://分

cal.add(Calendar.MINUTE, -num);

break;

case 5://秒

cal.add(Calendar.SECOND, -num);

break;

case 6://周

cal.add(Calendar.WEEK_OF_MONTH, -num);

break;

}

//通过格式化输出日期

SimpleDateFormat format = new java.text.SimpleDateFormat("yyyyMMddHHmmss");

// SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

if (type == 0) {

System.out.println("Today is: " + format.format(Calendar.getInstance().getTime()));

}

System.out.println("CutNum is: " + format.format(cal.getTime()));

String CutNum = format.format(cal.getTime());

return CutNum;

}

/**

* 时间日期加减(-前,+后)

*

* @param statTime

* @param ymdhms

* @param type

* @return

*/

public String timeNum(Date statTime, int ymdhms, int type) {

String tn = null;

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");

System.out.println("今天的日期:" + df.format(statTime));

System.out.println("两天前的日期:" + df.format(new Date(statTime.getTime() – 2 * 24 * 60 * 60 * 1000)));

System.out.println("三天后的日期:" + df.format(new Date(statTime.getTime() + 3 * 24 * 60 * 60 * 1000)));

switch (type) {

case 0://年

break;

case 1://月

break;

case 2://日

tn = df.format(new Date(statTime.getTime() – ymdhms * 24 * 60 * 60 * 1000));

break;

case 3://时

tn = df.format(new Date(statTime.getTime() – ymdhms * 60 * 60 * 1000));

break;

case 4://分

tn = df.format(new Date(statTime.getTime() – ymdhms * 60 * 1000));

break;

case 5://秒

tn = df.format(new Date(statTime.getTime() – ymdhms * 1000));

break;

}

return tn;

}

/**

* 时间日期加减(-前,+后)

*

* @param statTime

* @param year

* @param month

* @param day

* @param hour

* @param min

* @param sec

* @return

*/

public String timeNumStr(Date statTime, int year, int month, int day, int hour, int min, int sec) {

String tn = null;

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");

System.out.println("今天的日期:" + df.format(statTime));

System.out.println("两天前的日期:" + df.format(new Date(statTime.getTime() – 2 * 24 * 60 * 60 * 1000)));

System.out.println("三天后的日期:" + df.format(new Date(statTime.getTime() + 3 * 24 * 60 * 60 * 1000)));

tn = df.format(new Date(statTime.getTime() – day * hour * min * sec * 1000));

return tn;

}

}

5. 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, IntToLongpublic 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 blocke.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;}

6. android studio 时间戳s是string类型的吗

可以存储为String类型,通常时间戳不是String类型,而是long类型

Android Studio获取本地的时间戳通过下面方法:System.currentTimeMillis();

获取服务器的时间戳,通常返回的是一个字符串类型,即String,可以将其转换long类型使用对于方法:Long.parseLong(Strings)

7. 如何去掉android ota升级包时间戳

Android的OTA升级包中,里面有一个升级脚本,该脚本会检测recovey镜像的编译时间和OTA包的编译时间,如果recovey比OTA包的时间要新的话,升级便会失败。如果是这样的话,就得重新编译OTA包了。为了提供开发速度,可找到build/tools/releasetools/ota_from_target_files这个脚本,屏蔽一下这个函数 script.AssertOlderBuild(ts, ts_text),这样编译生成的OTA中便不会检测时间戳了。

8. android 仿qq聊天记录的时间戳

首先,看到这个效果,想一下实现的思路:弹出的待办和删除按钮,是通过dialog实现的。那么这个dialog就要能完成几个效果,第一:自定义界面,第二:控制dialog的显示位置,第三:点击dialog区域之外的地方,dialog要消失,第四:dialog显示的时候,activity不要变暗。下面就一步一步解决问题:1,自定义dialog[java] view plainpackage com.example.listitemdeletedemo; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; /** * @文件名称: MyDialog.java * @功能描述: 自定义dialog * @版本信息: Copyright (c)2014 * @开发人员: vincent * @版本日志: 1.0 * @创建时间: 2014年3月18日 下午1:45:38 */ public class MyDialog extends Dialog implements OnClickListener { private TextView leftTextView, rightTextView; private IDialogOnclickInterface dialogOnclickInterface; private Context context; public MyDialog(Context context, int theme) { super(context, theme); this.context = context; // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.layout_dialog); leftTextView = (TextView) findViewById(R.id.textview_one); rightTextView = (TextView) findViewById(R.id.textview_two); leftTextView.setOnClickListener(this); rightTextView.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub dialogOnclickInterface = (IDialogOnclickInterface) context; switch (v.getId()) { case R.id.textview_one: dialogOnclickInterface.leftOnclick(); break; case R.id.textview_two: dialogOnclickInterface.rightOnclick(); break; default: break; } } public interface IDialogOnclickInterface { void leftOnclick(); void rightOnclick(); } } 2,控制dialog显示位置 长按listview的item时。获取当前item在屏幕中的绝对位置,取其中的y值,即高度。根据listview item的height以及屏幕的高度,计算得到dialog的垂直位置,水平位置就直接居中就OK了[java] view plainint[] location = new int[2]; // 获取当前view在屏幕中的绝对位置 // ,location[0]表示view的x坐标值,location[1]表示view的坐标值 view.getLocationOnScreen(location); view.setBackgroundColor(getResources().getColor(R.color.blue)); currentItemView = view; longClickPosition = position; DisplayMetrics displayMetrics = new DisplayMetrics(); Display display = MainActivity.this.getWindowManager().getDefaultDisplay(); display.getMetrics(displayMetrics); WindowManager.LayoutParams params = myDialog.getWindow().getAttributes(); params.gravity = Gravity.BOTTOM; params.y =display.getHeight() – location[1]; myDialog.getWindow().setAttributes(params); myDialog.setCanceledOnTouchOutside(true); //点击dialog区域之外的地方,dialog消失 myDialog.show(); 3,dialog显示的时候,activity不变暗,这个在dialog的style中设置[html] view plain<style name="MyDialogStyle" parent="@android:Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@drawable/white</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:backgroundDimEnabled">false</item> </style> http://blog.csdn.net/jdsjlzx/article/details/42462229

9. 如何将android时间戳转换成时间 android怎么把时间戳转换成小时

mysql数据库的日期字段类型建议为varchar或者char,存入时间戳。取出的时候,将时间戳转换为你需要的时间格式就好。例:假设取出值为$timeecho date('Y-m-d H:i:s',$time);你就会看到:2011-11-23 17:42:43的时间格式


赞 (0)