Android Create/Show Digital Clock Widget Example with AM/PM

How to make digital clock inside android application to show current device time with AM-PM formats.

Digital clock is a simple clock with digital format like we have already seen on android phone title bar. Digital clock is used to show current device time with AM-PM formats in 12-hours format. So here is the complete step by tutorial for Android Create/Show Digital Clock Widget Example with AM/PM.

android-project-download-code-button

Android Create/Show Digital Clock Widget Example with AM/PM.

Code for MainActivity.java file.

package com.digitalclock_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.digitalclock_android_examples.com.MainActivity" >

 <DigitalClock
 android:id="@+id/digitalclock"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:textSize="25dp" />
 
</RelativeLayout>

Screenshot:

Android Create/Show Digital Clock Widget Example with AM/PM

Click here to download Android Create Digital Clock Widget Example with AM/PM project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *