package com.example.test_time;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import android.app.Activity;import android.os.Bundle;import android.util.Log;public class TimeActivity extends Activity{private long systemTimes;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);getSystemTime();//获取系统时间戳String string =transationSysTime("yyyy-MM-dd HH:mm:ss",1414994617);//已知时间戳(服务器)转换为标准格式Log.e("TAG", "===已知时间戳"+string);}public void getSystemTime(){//获取系统时间戳的几种方式//systemTimes = System.currentTimeMillis();//systemTimes = new Date().getTime();systemTimes = Calendar.getInstance().getTimeInMillis();Log.e("TAG","===系统时间戳="+systemTimes);//转换为标准时间格式SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");String time = dateFormat.format(systemTimes);Log.e("TAG","===系统时间="+time);}public String transationSysTime(String dateFormate,long timeType){if(timeType==0)return null;String result = "";timeType*=1000;SimpleDateFormat format = new SimpleDateFormat(dateFormate);result = format.format(new Date(timeType));transationTimetoInt(format,result);//将时间转换为Int类型,方便计算return result;}public void transationTimetoInt(SimpleDateFormat format,String resultStr){try {Date date = format.parse(resultStr);Calendar calendar = Calendar.getInstance();calendar.setTime(date);int year = calendar.get(Calendar.YEAR);int month = calendar.get(Calendar.MONTH);//month从0开始int day = calendar.get(Calendar.DAY_OF_MONTH);int hour = calendar.get(Calendar.HOUR_OF_DAY);int minute = calendar.get(Calendar.MINUTE);int seconds = calendar.get(Calendar.SECOND);Log.e("TAG","===转换为Int="+year+"年"+month+"月"+day+"日"+hour+"时"+minute+"分"+seconds+"秒");} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

更多相关文章

  1. Android(安卓)开发获取手机运行内存工具类
  2. Android(安卓)ContentProvider 使用limit
  3. android下为自己定义wifimanager类
  4. java 编译中常用函数
  5. JAVA-ANDROID
  6. 福利篇:学习编程视频免费领取
  7. Android7.0修改时间服务器
  8. Android(安卓)getIdentifier()使用
  9. Android(安卓)自定义自由选择时间区间的日历控件

随机推荐

  1. JAVA-全局变量与局部变量-继承-封装-(是三
  2. python 日志简单使用
  3. 关于反序列化时抛出java.io.EOFException
  4. 从RF、BB、AP、外设4个角度看手机的硬件
  5. 忽略转义字符时拆分字符串
  6. java中枚举enum的使用
  7. [刘阳Java]_了解BeanFactory_第4讲
  8. Java多线程六:线程优先级和yield()让步函
  9. JMeter-Java压力测试工具-02
  10. spring cloud微服务分布式云架构-Spring