【时间戳转换为日期工具apk源码实现】

将时间戳转换为日期,如windows7旗舰版程序中获取到的时间戳为:1377921697453,转换为日期后为:2013年08月23日 12时01分37秒。

  废话不说直接上源码:

  package com.jinhoward.timestamptodate;

  import com.jinhoward.timestamptodate.R;

  import android.app.Activity;

  import android.os.Bundle;

  import android.text.Editable;

  import android.util.Log;

  import android.view.View;

  import android.view.View.OnClickListener;

  import android.view.inputmethod.InputMethodManager;

  import android.widget.Button;

  import android.widget.EditText;

  import android.widget.TextView;

  import android.widget.Toast;

  import java.text.SimpleDateFormat;

  import java.util.Date;

  public class TimestampToDateActivity extends Activity {

  private String TagforCallLogs;

  public void onCreate(Bundle paramBundle) {

  super.onCreate(paramBundle);

  setContentView(R.layout.activity_timestamp_to_date);

  Button changeToDateButton = (Button) findViewById(R.id.changeToDateButton);

  changeToDateButton.setOnClickListener(new View.OnClickListener() {

  public void onClick(View paramView) {

  EditText localEditText = (EditText) TimestampToDateActivity.this

  .findViewById(R.id.numberEditText);

  SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(

  "yyyy年MM月dd日 HH时mm分ss秒");

  if (localEditText.getText().toString().equals("")) {

  Toast.makeText(TimestampToDateActivity.this, "您输入数值为空,请重新输入!",

  Toast.LENGTH_LONG).show();

  return;

  }

  //点击时间转换按钮后隐藏输入法框

  InputMethodManager inputMethodManager =(InputMethodManager)TimestampToDateActivity

  .this.getSystemService(INPUT_METHOD_SERVICE);

  inputMethodManager.hideSoftInputFromWindow(localEditText.getWindowToken(), 0);

  String str = localSimpleDateFormat.format(new Date(Long

  .parseLong(localEditText.getText().toString())));

  TextView showTimetTextView =(TextView)findViewById(R.id.showTime);

  showTimetTextView.setText(str);

  //              Log.v("stampToDate", Long.toString(System.currentTimeMillis()));

  }

  });

  }

  }

  xml文件源码:

  <?xml version="1.0" encoding="utf-8"?>

  <LinearLayout xmlns:android="schemas.android./apk/res/android"

  android:id="@+id/screen"

  android:layout_width="fill_parent"

  android:layout_height="fill_parent"

  android:background="#ffc1eeee"

  android:orientation="vertical" >

  <TextView

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:layout_marginTop="5.0dip"

  android:text="时间戳数值:"

  android:textSize="18.0sp"

  android:textStyle="bold" />

  <EditText

  android:id="@+id/numberEditText"

  android:layout_width="fill_parent"

  android:layout_height="wrap_content"

  android:layout_marginTop="5.0dip"

  android:focusable="true"

posted @ 2013-09-03 14:30  豆豆逗逗  阅读(240)  评论(0编辑  收藏  举报