本文主要是介绍AndroidStudio记录-时间TextClock使用(HH:mm,yyyy年MM月dd日 EEEE),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 结果显示
- 设置时区
- 设置显示格式
- 代码
- src\main\res\layout-v17\activity_main.xml
- MainActivity.java
结果显示
设置时区
String timeZone = "GMT+08:00";mHourMinuteTC.setTimeZone(timeZone);mYearMonthDayWeekTC.setTimeZone(timeZone);
设置显示格式
mHourMinuteTC.setFormat24Hour("HH:mm");mYearMonthDayWeekTC.setFormat24Hour("yyyy年MM月dd日 EEEE");
代码
src\main\res\layout-v17\activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TextClockandroid:id="@+id/tc_h_m"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:format24Hour="HH:mm"android:textColor="@color/black"android:textStyle="bold"android:textSize="50sp"/><TextClockandroid:id="@+id/tc_y_m_d_w"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:format24Hour="yyyy年MM月dd日 EEEE"android:textColor="@color/black"android:textSize="30sp"/></LinearLayout></RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {private TextClock mHourMinuteTC;private TextClock mYearMonthDayWeekTC;@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();setTime();}@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)private void initView(){mHourMinuteTC = (TextClock) findViewById(R.id.tc_h_m);mYearMonthDayWeekTC = (TextClock) findViewById(R.id.tc_y_m_d_w);}@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)private void setTime(){String timeZone = "GMT+08:00";mHourMinuteTC.setTimeZone(timeZone);mHourMinuteTC.setFormat24Hour("HH:mm");mYearMonthDayWeekTC.setTimeZone(timeZone);mYearMonthDayWeekTC.setFormat24Hour("yyyy年MM月dd日 EEEE");}
}
这篇关于AndroidStudio记录-时间TextClock使用(HH:mm,yyyy年MM月dd日 EEEE)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!