Pages

Showing posts with label Yesterday Date in android. Show all posts
Showing posts with label Yesterday Date in android. Show all posts

Wednesday, 14 December 2011

Current Date and Time in Android


// Today Date Format:Two Methods
Method 1.

        long msTime = System.currentTimeMillis();
        Date todayformat = new Date(msTime);
        Log.e("Date", "Current Date is :" + todayformat);

        Time todaydate = new Time();
        Log.e("Date", "Current Time with zone is :" + timenow);

        String timenow = todaydate.format2445();
        Log.e("Date", "Current Time and zone is :" + todaydate);

Method 2.
        Calendar todaycal = Calendar.getInstance();
        SimpleDateFormat dateFormattoday = new SimpleDateFormat("dd/MM/yyyy");
        todaycal.add(Calendar.DATE, 0);// 1 for tommarow
        String caltodaydate = dateFormattoday.format(todaycal.getTime());
        Log.e("Date", "Method 2-Current Date  is :" + caltodaydate);

String currenttime = todaycal.get(Calendar.HOUR) + ":"
                + todaycal.get(Calendar.MINUTE) + ":"
                + todaycal.get(Calendar.SECOND);
        Log.e("Date", "Method 2-Current Time  is :" + currenttime);By:
Yours
V.k.Hooda