【时间戳转换为日期工具apk源码实现】
2013-09-03 14:30
375 查看
将时间戳转换为日期,如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"
废话不说直接上源码:
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"
相关文章推荐
- 时间戳转换为日期工具apk源码实现
- 转换GMT秒数为日期时间格式-C#源码。
- 转换GMT秒数为日期时间格式-VC++源码。
- linux下 date命令实现 日期与时间戳互相转换
- Quartz动态添加、修改和删除定时任务时间的方法以及日期转换cron表达式时间格式工具类
- Android & Java DateUtils 拿来就用 包含常用的日期和时间转换的工具
- linux下date命令实现时间戳与日期的转换
- Excel日期/时间存储数值转换为具体日期/时间(java实现)
- mysql 时间转换 用EXCEL实现MySQL时间戳格式和日期格互转
- 站长工具之时间戳转换日期格式
- JS、Jquery实现---把后台传过来的时间毫秒数转换成想要的日期格式
- JS、Jquery实现---把后台传过来的时间毫秒数转换成想要的日期格式
- jquery中实现时间戳与日期相互转换
- mysql 时间转换 用EXCEL实现MySQL时间戳格式和日期格互转
- jquery中实现时间戳与日期相互转换
- java简单实现测试程序执行时间及日期转换字符串
- jq、js实现字符串转换日期计算时间差
- 微信小程序使用picker实现时间和日期选择框功能【附源码下载】
- js实现将时间戳转换为日期
- android开发时间和日期的代码实现工具类(一)