Kala J
Kala J

Reputation: 2070

How can I set my textClock to phone's default time format?

I have my TextClock Set as the following:

<TextClock
                android:id="@+id/datetime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_row="1"
                android:layout_column="2"
                android:textColor="@color/black"
                android:format24Hour="HH:mm"
                android:format12Hour="HH:mm"
                />

Right now even though my phone is defaulted to a 12 hour time, it's showing up as a 24 hour time.

I want to be able to set it to a 12 hour time zone but not permanently, only in regards to whatever my phone is set as. How can I do that?

EDIT:

I removed the format above but I am setting it again in the code like:

TextClock textClock = (TextClock) findViewById(R.id.datetime);
        textClock.setFormat12Hour("HH:mm");
        textClock.setFormat24Hour("HH:mm");

Would this also affect the phone's time zone?

I want to remove the AM/PM from the textclock when a format is not set in XML.

Upvotes: 1

Views: 2495

Answers (4)

Style-7
Style-7

Reputation: 1220

Replace:

android:format12Hour="hh:mm a" // 11:59 PM
android:format24Hour="HH:mm" // 23:59

Upvotes: 0

Leonid Shylin
Leonid Shylin

Reputation: 11

Also you can try this:

TextClock textClock = (TextClock) findViewById(R.id.datetime);
textClock.setFormat12Hour(null);

Upvotes: 0

Piyush
Piyush

Reputation: 1973

 <TextClock
            android:format12Hour="hh:mm"
            android:format24Hour="kk:mm"

            android:textSize="20sp"
            android:shadowColor="#7fffffff"
            android:shadowRadius="3.0"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

I used This code it is not showing me am/pm on my device.

Upvotes: 5

Galax
Galax

Reputation: 365

Just remove

android:format24Hour="HH:mm"
android:format12Hour="HH:mm"

This will make it so it automatically sets the format to what your phone is

Upvotes: 1

Related Questions