Pages

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

No comments:

Post a Comment