Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.widget.TimePicker;

public class Main {
    /**
     * Get time from TimePicker
     * 
     * @param timePicker
     * @return time string
     */
    public static String getStringTimeFromTimePicker(TimePicker timePicker) {
        String time = "";
        int hour = timePicker.getCurrentHour();
        int minute = timePicker.getCurrentMinute();
        time = getStringTimeFromTime(hour, minute);
        return time;
    }

    public static String getStringTimeFromTime(int hourofday, int minute) {
        String time = "";
        String AM_PM = "";
        if (hourofday < 12) {
            AM_PM = "AM";
        } else {
            hourofday -= 12;
            AM_PM = "PM";
        }
        time = hourofday + ":" + minute + " " + AM_PM;
        return time;
    }
}