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:
http://developer.android.com/reference/java/util/Calendar.html


Comments

Popular posts from this blog

Android Basic Tutorial : Circular Seek Bar

public class Welcome extends Activity {     CircularSeekBar circularSeekbar;
    @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         circularSeekbar = new CircularSeekBar(this);         circularSeekbar.setMaxProgress(100);         circularSeekbar.setProgress(100);         setContentView(circularSeekbar);         circularSeekbar.invalidate();
        circularSeekbar.setSeekBarChangeListener(new OnSeekChangeListener() {
            @Override             public void onProgressChange(CircularSeekBar view, int newProgress) {                 Log.d("Welcome", "Progress:" + view.getProgress() + "/" + view.getMaxProgress());             }         });
    } }