Java Time Format getTimeQuantum(String strDate, String format)

Here you can find the source of getTimeQuantum(String strDate, String format)

Description

get Time Quantum

License

Apache License

Declaration

public static String getTimeQuantum(String strDate, String format) 

Method Source Code

//package com.java2s;
/*//from w w w  . j a  va2s .c  om
 * Copyright (C) 2012 www.amsoft.cn
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String getTimeQuantum(String strDate, String format) {
        Date mDate = getDateByFormat(strDate, format);
        int hour = mDate.getHours();
        if (hour >= 12)
            return "PM";
        else
            return "AM";
    }

    public static Date getDateByFormat(String strDate, String format) {
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = mSimpleDateFormat.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. getTimeFromString(String time, SimpleDateFormat formatter)
  2. getTimeFromString(String timeStr, String format)
  3. getTimeInProvenanceFormat(Date date)
  4. getTimeOnlyDateFormat()
  5. getTimeOnlyWithNumber()
  6. getTimeStringFormatedForSWANWithDelim( final Object pObjTime, final String pStrDelim)
  7. getTimeSystem(String formatTime)
  8. getTwoTimeInterval(String startTime, String endTime, String format)
  9. getUniversalDateTimeFormat()