get Current Date Time in dd MMM yyyy hh:mm:ss a format - Android java.util

Android examples for java.util:Date Format

Description

get Current Date Time in dd MMM yyyy hh:mm:ss a format

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 getCurrentDateTime() {
        SimpleDateFormat sdf = new SimpleDateFormat(
                TIMESTAMP_DATE_FORMAT_12H);
        String currentDateandTime = sdf.format(new Date());
        return currentDateandTime;
    }/*from  ww w.  j a v  a  2  s.c  o m*/

}

Related Tutorials