This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Dhruv Joshi
Here is an example of how you could create a simple Android app that displays the current time and date:
First, install the Android Studio development environment and set it up on your computer.
Create a new project in Android Studio and choose "Empty Activity" as the template.
In the main activity layout file (activity_main.xml), add a TextView element to display the time and date.
In the MainActivity.java file, import the java.util.Calendar and java.text.SimpleDateFormat classes.
In the onCreate() method, get the current time and date using the Calendar and SimpleDateFormat classes, and set the text of the TextView element to the formatted time and date.
Run the app on an emulator or physical device to see the time and date displayed.
Here is an example of the code that you could use in the MainActivity.java file:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.Calendar;
import java.text.SimpleDateFormat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the current time and date
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String currentTime = dateFormat.format(calendar.getTime());
// Set the text of the TextView element to the formatted time and date
TextView textView = findViewById(R.id.textView);
textView.setText(currentTime);
}
}
This is just a basic example of how you could create an Android app that displays the current time and date. There are many other features and functionality that you could add to the app, depending on your needs and goals.
Thanks for reading!
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Dhruv Joshi
Dhruv Joshi | Sciencx (2022-12-25T16:02:59+00:00) How to make a simple Android app that shows time and date?. Retrieved from https://www.scien.cx/2022/12/25/how-to-make-a-simple-android-app-that-shows-time-and-date/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.