Java Minute Calculate toMinuteString(long time)

Here you can find the source of toMinuteString(long time)

Description

to Minute String

License

Open Source License

Declaration

public static String toMinuteString(long time) 

Method Source Code

//package com.java2s;
/**/* w ww . java  2s.com*/
 * This file is part of JEMMA - http://jemma.energy-home.org
 * (C) Copyright 2013 Telecom Italia (http://www.telecomitalia.it)
 *
 * JEMMA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL) version 3
 * or later as published by the Free Software Foundation, which accompanies
 * this distribution and is available at http://www.gnu.org/licenses/lgpl.html
 *
 * JEMMA 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 Lesser General Public License (LGPL) for more details.
 *
 */

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    public static final int MINUTES_IN_ONE_TIME_SLOT = 1;
    private static final SimpleDateFormat minutesFormatter = new SimpleDateFormat("EEE,kk:mm");

    public static String toMinuteString(long time) {
        return minutesFormatter.format(time);
    }

    public static String toMinuteString(Calendar c) {
        return minutesFormatter.format(c.getTimeInMillis());
    }

    public static String toMinuteString(int slot) {
        return minutesFormatter.format(getMillisOf(slot));
    }

    public static long getMillisOf(int slot) {
        return getCalendarOf(slot).getTimeInMillis();
    }

    public static Calendar getCalendarOf(int slot) {
        Calendar c = Calendar.getInstance();
        int minutes = slot * MINUTES_IN_ONE_TIME_SLOT;
        c.set(Calendar.HOUR_OF_DAY, minutes / 60);
        c.set(Calendar.MINUTE, minutes % 60);
        return c;
    }
}

Related

  1. plusMinute(int minute)
  2. setMinutes(Date date, int amount)
  3. shiftTime(Object o, int minutes)
  4. toDegreesMinutes(double degrees, int nDecimals, boolean longitude)
  5. toMinutes(Date fecha)