get Date Time String from Calendar as MM/dd/yyyy hh:mm:ss format - Android java.util

Android examples for java.util:Calendar Format

Description

get Date Time String from Calendar as MM/dd/yyyy hh:mm:ss format

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class Main {
    public static String getDateTimeString(Calendar calendar) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                "MM/dd/yyyy hh:mm:ss", Locale.US);
        simpleDateFormat.setLenient(false);
        return simpleDateFormat.format(calendar.getTime());
    }/*w  w  w.  j  ava 2s.  com*/
}

Related Tutorials