Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String getAmPmTimeString(int hr, int min) {
        boolean isAM = false;
        if (hr < 12) {
            isAM = true;
        } else if (hr > 12) {
            hr -= 12;
        }

        String hrStr = String.valueOf(hr);
        String minStr = String.valueOf(min);

        String timeStr = String.valueOf(hr) + ":";

        if (minStr.length() == 1) {
            minStr = "0" + minStr;
        }

        timeStr += minStr;

        if (isAM) {
            timeStr += " AM";
        } else {
            timeStr += " PM";
        }
        return timeStr;
    }
}