convert Time To Small Format - Android java.util

Android examples for java.util:Date Time

Description

convert Time To Small Format

Demo Code


//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static String convertTimeToSmallFormat(int hour, int minute) {
        String time = "";
        try {//from  w w w  . ja v a 2 s.c  o m
            String _24HourTime = String.valueOf(hour) + ":"
                    + String.valueOf(minute);
            SimpleDateFormat _24HourSDF = new SimpleDateFormat("HH:mm");
            SimpleDateFormat _12HourSDF = new SimpleDateFormat("hh:mm a");
            Date _24HourDt = _24HourSDF.parse(_24HourTime);
            time = _12HourSDF.format(_24HourDt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }
}

Related Tutorials