Java Date to Time getTimeDateByMinuteAndSeconds( Integer minutes, Integer seconds)

Here you can find the source of getTimeDateByMinuteAndSeconds( Integer minutes, Integer seconds)

Description

getTimeDateByMinuteAndSeconds: converts the minutes to an Date object {Category} TimestampUtil {talendTypes} Date {param} Integer(5): minutes {param} Integer(5): seconds {example} getTimeDateByMinuteAndSeconds(90,120).

License

Apache License

Declaration

public static java.util.Date getTimeDateByMinuteAndSeconds(
        Integer minutes, Integer seconds) 

Method Source Code

//package com.java2s;
/**//  www .jav  a 2s .  com
 * Copyright 2015 Jan Lolling jan.lolling@gmail.com
 * 
 * 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.
 */

public class Main {
    private static java.util.TimeZone utcTimeZone = null;

    /**
     * getTimeDateByMinuteAndSeconds: converts the minutes to an Date object
     * 
     * {Category} TimestampUtil
     * 
     * {talendTypes} Date
     * 
     * {param} Integer(5): minutes
     * {param} Integer(5): seconds
     * 
     * {example} getTimeDateByMinuteAndSeconds(90,120).
     */
    public static java.util.Date getTimeDateByMinuteAndSeconds(
            Integer minutes, Integer seconds) {
        if (minutes != null || seconds != null) {
            java.util.Calendar c = java.util.Calendar
                    .getInstance(getUTCTimeZone());
            c.setTime(new java.util.Date(0l));
            // cut minutes and seconds
            c.set(java.util.Calendar.HOUR_OF_DAY, 0);
            c.set(java.util.Calendar.MINUTE, 0);
            c.set(java.util.Calendar.SECOND, 0);
            if (minutes != null) {
                c.add(java.util.Calendar.MINUTE, minutes);
            }
            if (seconds != null) {
                c.add(java.util.Calendar.SECOND, seconds);
            }
            c.set(java.util.Calendar.MILLISECOND, 0);
            return c.getTime();
        } else {
            return null;
        }
    }

    private static java.util.TimeZone getUTCTimeZone() {
        if (utcTimeZone == null) {
            utcTimeZone = java.util.TimeZone.getTimeZone("UTC");
        }
        return utcTimeZone;
    }

    private static java.util.TimeZone getTimeZone(String idParam) {
        if (idParam == null || idParam.isEmpty()) {
            throw new IllegalArgumentException(
                    "id for time zone cannot be null or empty");
        }
        idParam = idParam.trim();
        String[] tzArray = java.util.TimeZone.getAvailableIDs();
        for (String id : tzArray) {
            if (id.equalsIgnoreCase(idParam)) {
                return java.util.TimeZone.getTimeZone(id);
            }
        }
        return null;
    }
}

Related

  1. getTimeAsXsdDateTime(Date d)
  2. getTimeBackInMillis(final int granularity, final int numberToBack, final Date date)
  3. getTimeBoxValue(TimeZone zone, Date date)
  4. getTimeByCustomPattern(Date date, String pattern)
  5. getTimeByOffset(Date reqDate, int offset)
  6. getTimeDateStr(Date date)
  7. getTimeDeltaValue(Date t, Date baseDate, String tDelta)
  8. getTimeFromDate(Date date)
  9. getTimeFromDate(final Date date)