Skip to main content

Android Basic Tutorial : Get the Current Date and Time

Here’s a code snipped to get the current date and/or time. This snipped uses the Calendar object (java.util.Calendar) which is a useful class when working with dates.

//Get a calendar object for the current date and time
Calendar CurrentDateTime = Calendar.getInstance();

//Example: Get current day of the month
int CurrentDay = fCalendar.get(Calendar.DAY_OF_MONTH);

//Example: Get current minutes
int CurrentMinutes = fCalendar.get(Calendar.MINUTE);

For more information see the Android SDK reference guide:


Popular posts from this blog

Sign In with Google in Your Android Apps Example with Code in Android Studio

1. Prerequisites

Before beginning, check that you have all the necessary pre-requisites. These include: Android StudioAn Android Device that runs Android 4.2.2 or later    -or-   A configured Android Emulator (this is available in Android Studio)The latest version of the Android SDK including the SDK tools component. You can get this from the Android SDK Manager in Android Studio.The Google Play Services SDK. You can get this from the Android SDK Manager in Android Studio.

2. Enabling Sign-In for your App
Before you start coding any of the Android functionality, you need to turn on the Sign-In APIs for your App in the Google Developer’s console. You’ll see how to do that in this section. Create a Project
To create a project, visit the developer’s console at:
Press the ‘Create Project’ button, and you’ll see a popup like this:

Enter a meaningful name for your project in the ‘Project name’ box. For the project ID, you’ll need to enter something tha…