Example usage for java.util Calendar MINUTE

List of usage examples for java.util Calendar MINUTE

Introduction

In this page you can find the example usage for java.util Calendar MINUTE.

Prototype

int MINUTE

To view the source code for java.util Calendar MINUTE.

Click Source Link

Document

Field number for get and set indicating the minute within the hour.

Usage

From source file:Main.java

static Date getExpirationDate(int tokenExpiredDateInMinuite) {
    final Calendar expiredTime = new GregorianCalendar();
    // access token is only valid for a hour
    expiredTime.add(Calendar.MINUTE, tokenExpiredDateInMinuite);

    return expiredTime.getTime();
}

From source file:Main.java

/**
 * Returns current date-time in format of yyyy-MM-dd hh:mm:ss
 * //  ww  w  . ja va2s .  c o  m
 * @return date time in string.
 */
public static String getCurrentTime() {
    int yyyy = Calendar.getInstance().get(Calendar.YEAR);
    int MM = Calendar.getInstance().get(Calendar.MONTH) + 1;
    int dd = Calendar.getInstance().get(Calendar.DATE);
    int hh = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    int mm = Calendar.getInstance().get(Calendar.MINUTE);
    int ss = Calendar.getInstance().get(Calendar.SECOND);
    String curDate = String.format("%04d-%02d-%02d %02d:%02d:%02d", yyyy, MM, dd, hh, mm, ss);

    return curDate;

}

From source file:MainClass.java

public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second,
        int millisecond) {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DATE, day);/*from  w w w.  j  a  v a2  s.  c o m*/
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);

    // now convert GregorianCalendar object to Timestamp object
    return new Timestamp(cal.getTimeInMillis());
}

From source file:Main.java

public static String buildShiftTimeRepresentation(Date shiftTime) {
    calendar.setTime(shiftTime);/*from w ww . java2  s  .c om*/

    String s = "";
    s = format.format(calendar.get(Calendar.HOUR) == 0 ? 12 : calendar.get(Calendar.HOUR));
    s += ":" + format.format(calendar.get(Calendar.MINUTE));
    s += calendar.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM";
    return s;
}

From source file:Main.java

public static ArrayList<Calendar> formatTimesForObject(String string) {
    ArrayList<Calendar> times = new ArrayList<>();
    for (String s : string.split(" ")) {
        int hour = Integer.valueOf(s.split(":")[0]);
        int minute = Integer.valueOf(s.split(":")[1]);

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        times.add(calendar);/*from w  ww. java  2  s . c  o m*/
    }
    return times;
}

From source file:Main.java

public static String formatDate(String date, int minutes) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date d = null;/*  ww  w .j  a v a 2s  .  co m*/
    try {
        d = sdf.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(d);
    calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - minutes);
    return sdf.format(calendar.getTime());
}

From source file:Main.java

private static void setAlarm(Calendar calendar, String sTime) {

    String speech[] = sTime.split(" ");
    String time = speech[0];/*from   w  w w  .  java 2  s  .c o m*/
    String timeParts[] = time.split(":");
    int hour = Integer.parseInt(timeParts[0]);
    int minute = Integer.parseInt(timeParts[1]);
    String ampm = speech[1].toUpperCase();
    if (ampm.startsWith("P")) {
        hour += 12;
    }
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
}

From source file:Main.java

public static long getYearStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_YEAR, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);/*from  w w  w  .  j av a  2s.c  o m*/
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long getPeriodStart(int periodType, long date) {
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(date);/*w  w  w  .  j  ava2s .c o m*/

    switch (periodType) {
    case TYPE_DAY: {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }

    case TYPE_WEEK: {
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        final int currentDayOfWeek = (cal.get(Calendar.DAY_OF_WEEK) + 7 - cal.getFirstDayOfWeek()) % 7;
        cal.add(Calendar.DAY_OF_YEAR, -currentDayOfWeek);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }

    case TYPE_MONTH: {
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }

    case TYPE_YEAR: {
        cal.set(Calendar.MONTH, 0);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }
    }
    return cal.getTimeInMillis();
}

From source file:Main.java

public static String getDateFromUTC(long timestamp) {
    if (timestamp == 0)
        timestamp = System.currentTimeMillis();
    Date date = new Date(timestamp);
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    cal.setTime(date);/*www .j  a  v  a 2  s .  c  om*/
    String val = (cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR) + ":"
            + cal.get(Calendar.MINUTE) + (cal.get(Calendar.AM_PM) == 0 ? "AM" : "PM"));

    //      final Date currentTime = new Date();
    //      final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z");
    //      sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    //      String ret = "UTC time: " + sdf.format(currentTime);
    //      System.out.println(ret);

    return val;
}