zoukankan      html  css  js  c++  java
  • 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;
    
        }
    
    
    }
  • 相关阅读:
    ZOJ 2158 Truck History
    Knight Moves (zoj 1091 poj2243)BFS
    poj 1270 Following Orders
    poj 2935 Basic Wall Maze (BFS)
    Holedox Moving (zoj 1361 poj 1324)bfs
    ZOJ 1083 Frame Stacking
    zoj 2193 Window Pains
    hdu1412{A} + {B}
    hdu2031进制转换
    openjudge最长单词
  • 原文地址:https://www.cnblogs.com/gisoracle/p/5010551.html
Copyright © 2011-2022 走看看