public class MainActivity extends Activity {
private DatePicker date_picker;
private TimePicker time_picker;
private TextView tv_date;
private TextView tv_time;
@Override
   protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//初始化
date_picker=(DatePicker) findViewById(R.id.date);
time_picker=(TimePicker) findViewById(R.id.time);
tv_date=(TextView) findViewById(R.id.tv_date);
tv_time=(TextView) findViewById(R.id.tv_time);
//获取当前的年月日时分信息
Calendar c=Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH);
int day=c.get(Calendar.DAY_OF_MONTH);
int hour=c.get(Calendar.HOUR_OF_DAY);
int minute=c.get(Calendar.MINUTE);
//使用Calendar显示时,月份从0开始,显示的时候加1
tv_date.setText("现在日期:"+year+"-"+(month+1)+"-"+day);
tv_time.setText("现在时间:"+hour+":"+minute);
 //初始化日期时候,需要日期监听器
date_picker.init(year, month, day, new OnDateChangedListener() ;{
//监听日期的改变
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
//Toast.makeText(MainActivity.this, "现在时间:"+year+"-"+(monthOfYear+1)+"-"+dayOfMonth, 0).show();
//月份以0开始统计,显示的时候要加1
tv_date.setText("现在日期:"+year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}
});
//设置时间为24小时制
time_picker.setIs24HourView(true);
//时间监听器
time_picker.setOnTimeChangedListener(new OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
tv_time.setText("现在时间:"+hourOfDay+":"+minute);
}
});

DataPicker以及TimePicker显示时间和日期(屏幕上显示)的更多相关文章

  1. 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程

    转自:http://blog.sina.com.cn/s/blog_957b9fdb0100zesv.html 为了说明在三维物体到二维图象之间,需要经过什么样的变换,我们引入了相机(Camera)模 ...

  2. 在屏幕上显示C盘根目录下的所有文件和文件夹

    1 import java.io.File; //在屏幕上显示C盘根目录下的所有文件和文件夹 public class ListDemo { public static void main(Strin ...

  3. 怎样在屏幕上显示多个alv

    本文解说怎样在屏幕上显示多个alv. 实现这种需求关键是下面几点(举例:在屏幕上显示4个alv): 1.须要定义4个alv control 2.由于有4个alv control,于是就须要定义4个容器 ...

  4. linux tail-在屏幕上显示指定文件的末尾若干行

    博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 tail命令用于输入文件中的尾部内容.tail命令默认在屏幕上显示指定文件的末尾10行.如果给定的文件不止一个,则在显示的每个 ...

  5. DatePickerDialog和TimePickerDialog(基于对话框显示时间和日期)

    public class MainActivity extends Activity implements android.view.View.OnClickListener{ private But ...

  6. iOS开发中获取视图在屏幕上显示的位置

    在iOS开发中,我们会经常遇到一个问题,例如,点击一个按钮,弹出一个遮罩层,上面显示一个弹框,弹框显示的位置在按钮附近.如果这个按钮的位置相对于屏幕边缘的距离是固定的,那就容易了,可以直接写死位置.可 ...

  7. Droid@screen:在PC屏幕上显示Android手机屏幕

    这里介绍一款工具——Droid@screen,用来获取手机屏幕,显示在PC屏幕上.它集截图.录像等多种功能于一体. 安装 1.    下载地址:http://droid-at-screen.org/d ...

  8. 【iCore4 双核心板_ARM】例程十:RTC实时时钟实验——显示时间和日期

    实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ RTC_TimeTypeDef sTime; RTC_DateTypeDef sDate; ; ...

  9. 【iCore1S 双核心板_ARM】例程十一:RTC实时时钟实验——显示时间和日期

    实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ RTC_DateTypeDef sDate; RTC_TimeTypeDef sTime; u ...

随机推荐

  1. CF 888E Maximum Subsequence——折半搜索

    题目:http://codeforces.com/contest/888/problem/E 一看就是折半搜索?……然后排序双指针. 两个<m的数加起来如果>=m,一定不会更新答案.因为- ...

  2. AtCoder Regular Contest 063 E:Integers on a Tree

    题目传送门:https://arc063.contest.atcoder.jp/tasks/arc063_c 题目翻译 给你一个树,上面有\(k\)个点有权值,问你是否能把剩下的\(n-k\)个点全部 ...

  3. bzoj 3745 [Coci2015]Norma——序列分治

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3745 如果分治,就能在本层仅算过 mid 的区间了. 可以从中间到左边地遍历左边,给右边两个 ...

  4. Android四种启动模式

    四种启动模式 standard(默认) singleTop singleTast singleInstance standard(默认) 系统默认的启动模式. Android是使用返回栈来管理活动的, ...

  5. android自动化测试之uiautomator

    1.通过monkeyrunner.bat   monkey_record.py启动MonkeyRecorder进行拿到各个控件的坐标(要连上手机才可以启动) 2.也可以通过uiautomatorvie ...

  6. hibernate 学习 五 hibernate核心接口

    一 Configuration接口 Configuration对象只存在于系统的初始化阶段.配置相关. 配置文件可以使用默认的路径,也可以指定路径. Configuration config = ne ...

  7. bzoj5117

    线段树 先看前三个操作,都是区间修改,我们对于信息维护一个二元组(a,b),表示x=max(x+a,b),那么第一个操作就是(a,-inf),第二个是(-a,0),第三个是(-inf,a) 然后看查询 ...

  8. HttpPost 传输Json数据并解析

    转自:https://blog.csdn.net/qq_35114086/article/details/52317311 这里写个测试用例模拟外部调用,通过httppost 传递一个json封装的表 ...

  9. 【转载】“error LNK1169: 找到一个或多个多重定义的符号”的解决方法

    c++的小细节的地方 原文地址:https://blog.csdn.net/xiaosu123/article/details/5665729 问题描述如下: 有 三个源文件,A.h.B.cpp.C. ...

  10. ubuntu的 mysql 存储目录迁移

    1:sudo service MySQL stop#迁移前必须先停止mysql 2:创建mysql 存放的 目标文件夹 一般 默认的 mysql 存储目录在  /var/lib中 看清楚  文件的权限 ...