android 获得系统时间
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <!-- 显示网络状态的标签控件 -->
<TextView
android:id="@+id/myyl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp" /> </RelativeLayout>
package com.example.yanlei.yl; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.DateFormat;
import android.widget.TextView; import java.text.SimpleDateFormat;
import java.util.Calendar; public class MainActivity extends AppCompatActivity { private TextView pTextView; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); pTextView = (TextView) findViewById(R.id.myyl);
SimpleDateFormat sDateFormat; String date; if (DateFormat.is24HourFormat(getApplicationContext())) {
sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = sDateFormat.format(new java.util.Date()); } else {
sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = sDateFormat.format(new java.util.Date()) + getPeroidText(); }
pTextView.setText("时间:" + date);
} private CharSequence getPeroidText() { String am_pm = Calendar.getInstance().getTime().getHours() >= 12 ? "PM" : "AM"; return am_pm; } }
android 获得系统时间的更多相关文章
- Android获取系统时间方法的总结
Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...
- android开发 系统时间与定时器之间有关系嘛?
如题: android开发 系统时间与定时器之间有关系嘛? 答案:有. 看定时器源码: /* * Schedule a task. */ private void scheduleImpl(Timer ...
- Android 获取系统时间和网络时间
有些时候我们的应用中只能使用网络时间,而不能使用系统的时间,这是为了避免用户关闭了使用网络时间的功能后所产生的误差. 直接上代码. 1.清单文件中网络添加权限. <!-- 访问Internet资 ...
- Android获取系统时间的多种方法
Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...
- Android取得系统时间
Time t = new Time();//实例化Time类 t.setToNow();//取得当前的系统时间 int month = t.month;//获取月 int year = t.year; ...
- Android获取系统时间yyyyMMddHHmmssSSS
代码改变世界 public String testTime1() throws ParseException { String DEFAULT_TIME_FORMAT = "yyyy-MM- ...
- (转+原)android获取系统时间
参考的网站如下: http://c.biancheng.net/cpp/html/144.html http://www.linuxidc.com/Linux/2012-03/55909.htm 代码 ...
- Android获取网络时间的方法
一.通过免费或者收费的API接口获取 1.免费 QQ:http://cgi.im.qq.com/cgi-bin/cgi_svrtime 淘宝:http://api.m.taobao.com/rest/ ...
- android BroadcastReceiver ACTION_TIME_TICK 系统时间监听不到
android BroadcastReceiver ACTION_TIME_TICK 系统时间监听不到 今天做android上的消息推送,启动了一个独立service,然后在里面监听系统的ACTION ...
随机推荐
- (37)zabbix snmp类型 无需安装agent也能监控
概述 如果我们需要监控打印机.路由器.UPS等设备,肯定不能使用zabbix agentd,因为他们不能安装软件的,还好他们一般都支持SNMP协议,这样我可以使用SNMP来监控他们.如果你希望使用SN ...
- verilog behavioral modeling --loop statement
1.forever 2.repeat 3.while 4.for The for statement accomplishes the same results as the following ps ...
- linux文件权限更改命令chmod及数字权限
chmod -change file mode bits :更改文件权限 chmod是用来改变文件或者目录权限的命令,但只有文件的属主和超级用户(root)才有这种权限. 更改文件权限的2种方式: 一 ...
- centos7 安装rabbitmq rabbitmq-c以及amqp扩展 详细篇
自己鼓捣了一晚上总算整明白了,有几个坑分享给小伙伴,希望能帮到你 前期准备 安装erlang 下载rpm包地址:https://github.com/rabbitmq/erlang-rpm (注意er ...
- python中set()函数的用法
set顾名思义是集合,里面不能包含重复的元素,接收一个list作为参数 list1=[1,2,3,4] s=set(list1) print(s) #逐个遍历 for i in s: print(i) ...
- eclipse错误日志
一.普通错误:(必现) 1.空指针: 2. 数组下标溢出,越界 3. 数组下标定义为双精度不妥,应该是整数 4. 类型转换错误(与手机分辨率有关) 二. 数据库错误:(必现) 1. 数据库,报错(数 ...
- 学习笔记5——wp主题开发
我觉得学习wordpress插件开发之前还是得先理解一下wp的主题开发,循序渐进才能学好wordpress开发,话不多说,接下来整理一下这两天学习的wordpress主题开发的一些心得和体会,与大家一 ...
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
先把代码扔上来 E. Field of Wonders time limit per test 3 seconds memory limit per test 256 megabytes input ...
- MySQL5.7 服务 crash 后无法启动
事发背景 测试环境更换数据盘,直接采取在线将数据目录暴力拷贝到新盘,然后将原服务关闭,启用新盘. 服务是可以正常启动的,但是没多会开发就反应服务down了,错误日志输出 -- :: InnoDB: F ...
- BZOJ 2176 Strange string ——最小表示法
本来想用来练习后缀自动机的,但是100w有点虚(事实证明确实T掉了). 只好上最小表示法. #include <cstdio> #include <cstring> #incl ...