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 ...
随机推荐
- noip_最后一遍_1-数学部分
它就是要来了 noip数论一般会以三种形式呈现 注 码风可能有些毒 (有人说我压行qwq) 大概保持标准三十五行左右 为什么是三十五行呢 因为我喜欢这个数字 我喜欢三十五而已(足球球衣也会用这个号哒) ...
- LeetCode 买卖股票的最佳时机
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润. 注意你不能在买入股票前卖出股票. 示例 ...
- bzoj5138 [Usaco2017 Dec]Push a Box
题目描述: bz luogu 题解: 暴力可以记录$AB$位置转移,这个时候状态是$n^4$的,无法接受. 考虑只记录$A$在$B$旁边时的状态,这个时候状态时$n^2$的. 所以说转移有两种,一种是 ...
- 【树形背包】bzoj4033: [HAOI2015]树上染色
仔细思考后会发现和51nod1677 treecnt有异曲同工之妙 Description 有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并 ...
- centOS下jenkins
转:centos7搭建jenkins小记 转自:https://segmentfault.com/a/1190000007086764 安装java环境 1.查看服务器版本 centos7,继续. c ...
- Juqyer:$.ajax()方法详解
Jquery中的ajax方法参数总是记不住,这里记录一下. 最常用的属性是:url.data 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为S ...
- cs231n课程索引
课程资源 课程官网 课程视频-youtube 课程视频-字幕版 官方笔记 官方笔记-中文版 课程作业参考答案
- WEB框架——WEB框架本质
武sir http://www.cnblogs.com/wupeiqi/articles/5237672.html
- kali2018利用ss和ProxyChains实现任意应用代理
第一步:配置ss 第二步:配置proxychain vim /etc/proxychains.conf 第三步:使用proxychains 终端输入: proxychains firefox 通过代理 ...
- BZOJ 2693 jzptab ——莫比乌斯反演
同BZOJ 2154 但是需要优化 $ans=\sum_{d<=n}d*\sum_{i<=\lfloor n/d \rfloor} i^2 *\mu(i)* Sum(\lfloor \fr ...