Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Display current time that changes dynamically for every second in android

Tags:

android

I need to display the current time in a textview and the time changes dynamically for every second (Like the digital clock) in android.. I have googled but i didnt get the help.If Anyone have the idea for this, please help me Thanks in advance.

like image 264
Navamani Samuel Avatar asked May 17 '12 10:05

Navamani Samuel


People also ask

How to get current time of system in Android?

Date; Date currentTime = Calendar. getInstance(). getTime();

Which view is used to display the date and time in Android application?

text. DateFormat. getDateTimeInstance(). format(new Date()); // textView is the TextView view that should display it textView.


1 Answers

Use TextClock. this wil change dynamically without having a separate code.

        <TextClock
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/textClock"
            android:layout_weight="0.11"
            android:textStyle="bold"
            android:textSize="22sp"
            android:format24hours="hh:mm:ss a  EEE MMM d"/>

    TextClock textClock = (TextClock) findViewById(R.id.textClock);
    textClock.setFormat12Hour(null);
    //textClock.setFormat24Hour("dd/MM/yyyy hh:mm:ss a");
    textClock.setFormat24Hour("hh:mm:ss a  EEE MMM d");
like image 120
Nikhil Dinesh Avatar answered Sep 22 '22 19:09

Nikhil Dinesh