Android基础TOP2_1:输出系统时间

Activity:

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

  JAVA:

 //获取TextView
        TextView tv=(TextView)findViewById(R.id.tv);
        //调用Date类
        Date now=new Date();
        //设置时间显示格式
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String sj=sdf.format(now);
        tv.setText("现在时间:"+sj);
        }

 //获取TextView
        TextView tv=(TextView)findViewById(R.id.tv);
        //调用Date类
        Date now=new Date();
        //设置时间显示格式
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String sj=sdf.format(now);
        tv.setText("现在时间:"+sj);
        }
原文地址:https://www.cnblogs.com/AndroidCSY/p/6681525.html