convert Time Stamp in dd MMM yyyy hh:mm:ss a format To Date - Android java.util

Android examples for java.util:Date Parse

Description

convert Time Stamp in dd MMM yyyy hh:mm:ss a format To Date

Demo Code

import android.content.Context;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{
    public static final String TIMESTAMP_DATE_FORMAT_12H = "dd MMM yyyy hh:mm:ss a";
    public static String convertTimeStampToDate(long timeStamp) {
        SimpleDateFormat objFormatter = new SimpleDateFormat(
                TIMESTAMP_DATE_FORMAT_12H);
        objFormatter.setTimeZone(TimeZone.getDefault());

        Calendar objCalendar = Calendar.getInstance(TimeZone.getDefault());
        objCalendar.setTimeInMillis(timeStamp);
        String result = objFormatter.format(objCalendar.getTime());
        objCalendar.clear();//  w  w w . j av a  2  s . co  m
        return result;
    }

}

Related Tutorials