<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 获得系统时间的更多相关文章

  1. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

  2. android开发 系统时间与定时器之间有关系嘛?

    如题: android开发 系统时间与定时器之间有关系嘛? 答案:有. 看定时器源码: /* * Schedule a task. */ private void scheduleImpl(Timer ...

  3. Android 获取系统时间和网络时间

    有些时候我们的应用中只能使用网络时间,而不能使用系统的时间,这是为了避免用户关闭了使用网络时间的功能后所产生的误差. 直接上代码. 1.清单文件中网络添加权限. <!-- 访问Internet资 ...

  4. Android获取系统时间的多种方法

    Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...

  5. Android取得系统时间

    Time t = new Time();//实例化Time类 t.setToNow();//取得当前的系统时间 int month = t.month;//获取月 int year = t.year; ...

  6. Android获取系统时间yyyyMMddHHmmssSSS

    代码改变世界 public String testTime1() throws ParseException { String DEFAULT_TIME_FORMAT = "yyyy-MM- ...

  7. (转+原)android获取系统时间

    参考的网站如下: http://c.biancheng.net/cpp/html/144.html http://www.linuxidc.com/Linux/2012-03/55909.htm 代码 ...

  8. Android获取网络时间的方法

    一.通过免费或者收费的API接口获取 1.免费 QQ:http://cgi.im.qq.com/cgi-bin/cgi_svrtime 淘宝:http://api.m.taobao.com/rest/ ...

  9. android BroadcastReceiver ACTION_TIME_TICK 系统时间监听不到

    android BroadcastReceiver ACTION_TIME_TICK 系统时间监听不到 今天做android上的消息推送,启动了一个独立service,然后在里面监听系统的ACTION ...

随机推荐

  1. 268. Missing Number@python

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  2. 使用Spring Cloud需要了解一些概念

    Spring Cloud是一个基于Spring Boot实现的微服务架构开发工具,它为基于JVM的微服务开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集 ...

  3. MySQL中日期函数的使用

    1. MySQL中日期函数的使用 1.1. 转DATETIME类型为Date类型 将add_time ::56转化为date类型 select * from product where Date(ad ...

  4. Python编程快速上手--实践项目11.11.1

    from selenium import webdriver from selenium.webdriver.common.keys import Keys import time def messa ...

  5. C++ 字符串分割,并把子字符串转换成int型整数

    主要涉及到string类的两个函数find和substr: find()函数的用法: 原型:size_t find ( const string& str, size_t pos = 0 ) ...

  6. java null 空指针

    对于Java程序员来说,null是令人头痛的东西.时常会受到空指针异常(NPE)的骚扰.连Java的发明者都承认这是他的一项巨大失误.Java为什么要保留null呢?null出现有一段时间了,并且我认 ...

  7. HP DL380 G5 安装操作系统流程

    1.准备服务器引导盘,设置光盘启动.注意:会将服务器所有数据清除 2.依据引导盘选择需要的安装系统 3.插入系统安装光盘.ps:若kvm等远程工具无法插入光盘,需要插入物理介质的安装光盘

  8. 对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App)

    对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App) 实验目的:对比使用Charles和Fiddler两个工具 实验对象:车易通App,易销通App 实验结果 ...

  9. python-通过openpy操作excel

    1.安装 openpyxl pip install openpyxl == 2.3.5  安装指定版本 遇到问题: 查询结果:这是因为电脑上有其他软件也有pip命令,我的电脑上是因为装了loadrun ...

  10. python jieba包用法总结

    # coding: utf-8 # ###jieba特性介绍 # 支持三种分词模式: # 精确模式,试图将句子最精确地切开,适合文本分析: # 全模式,把句子中所有的可以成词的词语都扫描出来, 速度非 ...