【问题标题】:TextClock returns different valueTextClock 返回不同的值
【发布时间】:2017-11-01 20:27:41
【问题描述】:

我正在尝试在 Android Studio 上制作一种带有某些时区的时钟。

我放了一个 TextClock,在我的布局中这个 TextClock 出现 this way

但是当我运行应用程序时,结果完全不同,like this。它返回一个完全不同的小时..

这是 TextClock 的 XML 代码:

 <android.widget.TextClock
    android:id="@+id/fuso"
    android:layout_width="344dp"
    android:layout_height="101dp"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:format12Hour="@null"
    android:format24Hour="dd/MM/yyyy HH:mm:ss"
    android:textSize="30sp"
    android:timeZone="America/Los Angeles"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintVertical_bias="0.206" />

我能做什么?为什么我运行应用时android:timeZone="America/Los Angeles" 不起作用?

我需要添加一些东西吗?

谢谢。

【问题讨论】:

  • 检查你的android:format12Hour="@null" android:format24Hour="dd/MM/yyyy HH:mm:ss" 两个标签
  • @JaydipUmaretiya 我试图删除 'android:format12Hour="@null" ' 但小时仍然不同

标签: java android android-studio timezone


【解决方案1】:

试试这样。指定android:format12Hour="hh:mm:ss a"

<TextClock
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:format12Hour="hh:mm:ss a"
    android:gravity="center_horizontal"
    android:textColor="#d41709"
    android:textSize="44sp"
    android:textStyle="bold" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-08
    • 2014-03-29
    • 2018-02-19
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多