在屏幕上显示日期时间星期的方法

一个获取当前时间的类:

  1 import android.annotation.SuppressLint;
  2 import android.os.Handler;
  3 import android.os.Message;
  4 import android.util.Log;
  5 import android.widget.TextView;
  6
  7 import com.acmeinte.idl.sample.common.Constants;
  8 import com.acmeinte.idl.sample.common.EventMsg;
  9 import com.acmeinte.idl.sample.manager.DBFileManager;
 10 import com.acmeinte.idl.sample.manager.DataMessage;
 11
 12 import org.greenrobot.eventbus.EventBus;
 13
 14 import java.text.SimpleDateFormat;
 15 import java.util.Calendar;
 16 import java.util.Date;
 17 import java.util.TimeZone;
 18
 19 //***
 20 //更新时间类
 21 //***
 22 public class ThreadTime extends Thread {
 23     public TextView tvDate;
 24     private int msgKey1 = 22;
 25
 26     public ThreadTime(TextView tvDate) {
 27         this.tvDate = tvDate;
 28     }
 29
 30     @Override
 31     public void run() {
 32         do {
 33             try {
 34                 Thread.sleep(1000);
 35                 Message msg = new Message();
 36                 msg.what = msgKey1;
 37                 mHandler.sendMessage(msg);
 38             } catch (InterruptedException e) {
 39                 e.printStackTrace();
 40             }
 41         } while (true);
 42     }
 43
 44
 45     @SuppressLint("HandlerLeak")
 46     private Handler mHandler = new Handler() {
 47         @SuppressLint("SetTextI18n")
 48         @Override
 49         public void handleMessage(Message msg) {
 50             super.handleMessage(msg);
 51             switch (msg.what) {
 52                 case 22:
 53                     SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
 54                     String date = sdf.format(new Date());
 55                     tvDate.setText(deviceTime() + date + " " + getWeek());
 56                     65                     break;
 66                 default:
 67                     break;
 68             }
 69         }
 70     };
 71
 72     /**
 73      * 获取今天星期几
 74      *
 75      * @return
 76      */
 77     public static String deviceTime() {
 78         Calendar calendar = Calendar.getInstance();
 79         calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
 80         String year;
 81         String month;
 82         String day;
 83         String deviceTime;
 84
 85         year = String.valueOf(calendar.get(Calendar.YEAR));
 86         month = String.valueOf(calendar.get(Calendar.MONTH) + 1);
 87         day = String.valueOf(calendar.get(Calendar.DATE));
 88         deviceTime = year + "-" + month + "-" + day + " ";
 89
 90         return deviceTime;
 91     }
 92
 93     /**
 94      * 获取今天星期几
 95      *
 96      * @return
 97      */
 98     public static String getWeek() {
 99         Calendar calendar = Calendar.getInstance();
100         int i = calendar.get(Calendar.DAY_OF_WEEK);
101         switch (i) {
102             case 1:
103                 return "周日";
104             case 2:
105                 return "周一";
106             case 3:
107                 return "周二";
108             case 4:
109                 return "周三";
110             case 5:
111                 return "周四";
112             case 6:
113                 return "周五";
114             case 7:
115                 return "周六";
116             default:
117                 return "";
118         }
119     }
120
121  131 }

然后再UI界面修改txt参数实现时间显示:

1 //时间
2
3         TextView time_device ;
4         time_device = findViewById(R.id.txt_time_device);
5         ThreadTime threadTime = new ThreadTime(time_device);
6         threadTime.start();

原文地址:https://www.cnblogs.com/bbqopdd/p/10890044.html

时间: 2024-08-12 18:20:53

在屏幕上显示日期时间星期的方法的相关文章

在屏幕上显示日志的Android类库

Galgo是Android日志类库,用于在屏幕上显示应用的日志信息.这对于测试人员和开发人员非常有用,可以根据屏幕上的日志文件了解应用出现BUG时发生的事情. 可以定义屏幕上显示日志的背景颜色.文本颜色.文本大小和日志显示的行数. https://github.com/inaka/galgo public class ExampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceS

46.编写程序在屏幕上显示如下图形

1 2 3 4 55 1 2 3 44 5 1 2 33 4 5 1 2 2 3 4 5 1 (1)运用循环嵌套,并设置中间变量转换 //1.新建一个数组//2.输入内容并存储//3.输出结果 #include<iostream> using namespace std; int main() { int temp; int a[5]={1,2,3,4,5}; for(int m=0;m<5;m++) { cout<<a[m]<<" "; }

怎样在屏幕上显示多个alv

本文解说怎样在屏幕上显示多个alv. 实现这种需求关键是下面几点(举例:在屏幕上显示4个alv): 1.须要定义4个alv control 2.由于有4个alv control,于是就须要定义4个容器装这4个控件 3.为了合理布局这4个容器,就要将这4个容器嵌入另外一个splitter 容器中 4.可是splitter容器又仅仅能置入其它容器中,那么就须要再定义一个容器 总之,须要3层容器和1层控件,总共要定义6个容器和4个控件 5.最里面的容器应该是cl_gui_custom_containe

如何在屏幕上显示多个alv

本文讲解如何在屏幕上显示多个alv. 实现这样的需求关键是以下几点(举例:在屏幕上显示4个alv): 1.需要定义4个alv control 2.因为有4个alv control,于是就需要定义4个容器装这4个控件 3.为了合理布局这4个容器,就要将这4个容器嵌入另外一个splitter 容器中 4.但是splitter容器又只能置入其他容器中,那么就需要再定义一个容器 总之,需要3层容器和1层控件,总共要定义6个容器和4个控件 5.最里面的容器应该是cl_gui_custom_containe

汇编一点点提高3——键盘输入8位二进制数,存入NUM单元,并在屏幕上显示对应的16进制数

此程序要注意一下几点: 1.dos1号功能--带回显的键盘输入,自动存入al 2.dos7号功能--不带回显的键盘输入,自动存入al,若要在屏幕中显示要调用DOS2号功能 3.将输入的多个二进制数转换为ASCII码 input:  mov ah,1  int 21h  add bl,bl  cmp al,'1'  jnz P1  inc bl  P1: dec ch  jnz input 4.换行子程序: newline: mov ah,2 mov dl,13 int 21h mov ah,2

02 :history命令显示日期-时间-登录IP-用户名

 如何让history命令显示日期-时间-登录IP-用户名 修改: vim /etc/bashrc 在文件最后面加入如下两行: USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}]" 重新加载环境变量: Source /etc/bashrc 再次执行history ,历史命令就会显示出时

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

在iOS开发中,我们会经常遇到一个问题,例如,点击一个按钮,弹出一个遮罩层,上面显示一个弹框,弹框显示的位置在按钮附近.如果这个按钮的位置相对于屏幕边缘的距离是固定的,那就容易了,可以直接写死位置.可是,如果按钮是在UITableView的cell上呢?随着UITableView的滚动,按钮可能在顶部,也可能在底部,还可能在中间,左侧.右侧都有可能,那么,这个时候,怎么去计算按钮所在的位置呢?如果按钮所在的UITabelView是在另外一个UIScrollView的一个cell上呢?如果外面再有

01_SDL_在屏幕上显示一张图片

#include "SDL/SDL.h" #include <string> //屏幕属性 const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; //能被使用到的面 SDL_Surface *message = NULL; SDL_Surface *background = NULL; SDL_Surface *screen = NULL; SDL_Su

[email&#160;protected]:在PC屏幕上显示Android手机屏幕

这里介绍一款工具——[email protected],用来获取手机屏幕,显示在PC屏幕上.它集截图.录像等多种功能于一体. 安装 1.    下载地址:http://droid-at-screen.org/download.html,下载后是一个jar包,放到某个目录就可以. 2.    安装JDK6或以上版本 3.    安装Android SDK(从Android官方下载一个完整包解压即可) 4.    设置ANDROID_HOME环境变量指向AndroidSDK主目录(这步如果不做,则需