get Am Pm - Java java.util

Java examples for java.util:AM PM

Description

get Am Pm

Demo Code

/*/*from  w w w.  jav  a  2  s  . c o  m*/
 * @(#)CalendarUtil.java
 *
 * Copyright (c) 2002 CNM Technologies, Inc.
 * All Rights Reserved.
 *
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String time = "java2s.com";
        System.out.println(getAmPm(time));
    }

    public static String getAmPm(String time) {
        int hour = Integer.parseInt(time.substring(0, 2));
        String res;

        if (hour >= 12)
            res = "PM";
        else
            res = "AM";

        return res;
    }
}

Related Tutorials