Java Calendar Time getTimeToString(Calendar argCal)

Here you can find the source of getTimeToString(Calendar argCal)

Description

Return [HH]h[mm]

License

Open Source License

Declaration

public static String getTimeToString(Calendar argCal) 

Method Source Code


//package com.java2s;
/*//from ww w .j a  v  a 2s. c  o m
Copyright 2005-2015, Olivier PETRUCCI.
    
This file is part of Areca.
    
Areca is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
Areca is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Areca; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    
*/

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    public static final String TIME_SEPARATOR = "h";

    /**
     * Return [HH]h[mm] 
     */
    public static String getTimeToString(Calendar argCal) {
        Calendar cal = argCal;
        if (cal == null) {
            cal = new GregorianCalendar();
        }

        String date = "";
        if (cal.get(Calendar.HOUR_OF_DAY) < 10) {
            date += "0";
        }
        date += cal.get(Calendar.HOUR_OF_DAY) + TIME_SEPARATOR;

        if (cal.get(Calendar.MINUTE) < 10) {
            date += "0";
        }
        date += cal.get(Calendar.MINUTE);

        return date;
    }

    public static String getTimeToString() {
        return getTimeToString(null);
    }
}

Related

  1. getTime(Calendar cal)
  2. getTime(Date date, int CalendarType, int interval)
  3. getTimeFrame(final Calendar calFrom, final Calendar calTo)
  4. getTimeInHHMMSS(Calendar time)
  5. getTimeStr(Calendar cal)
  6. getTimeValue(Calendar cal)
  7. getTimeYYYYMMDD(Calendar calendar)
  8. getTimeZone(Calendar cal)
  9. getTimeZoneCalendar(final TimeZone timeZone)