Thursday, June 18, 2015

Convert timestamp to date and time in android

Here Timestamp means UNIX timestamp,convert to date and time in android. suppose timestamp is 1434624342http://www.currenttimestamp.com/) and show into DD-MM-YYYY and HH:MM  format.

           long time=1434624342;
           Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    cal.setTimeInMillis(time);
    String date = DateFormat.format("dd-MM-yyyy hh:mma", cal).toString();


        Date and Time Format : 18-06-2015 10:47AM

     If timestamp is String then convert to long by:

    String timestamp=Long.parseLong(long_value);

Note: import 
                     import java.util.Calendar;
                      import java.util.Locale;

NOTE:  If any issue to implement this code then please comment...

No comments :

Post a Comment