Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

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

Prototype

int SECOND

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

Click Source Link

Document

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

Usage

From source file:Main.java

public static Date getDateTimeFrom(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_MONTH, 0);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.YEAR, 0);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Date ret = calendar.getTime();
    return ret;/*from w w  w .ja  v  a2s . c  o  m*/
}

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);/*from w  w w  .ja  v  a2s  .c  om*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static void setTimerReceiver(Context context, int repeat_time, Class<?> class_name) {
    AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intentReceiver = new Intent(context, class_name);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentReceiver,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, repeat_time / 1000);

    // InexactRepeating allows Android to optimize the energy consumption
    alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), repeat_time, pendingIntent);
}

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  a  v  a 2 s .co 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 boolean isCheckChangePermitted(Context context, Calendar date) {

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    String limitActivePref = sharedPrefs.getString("active-date-key", "ALLOW_ALL");

    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    Calendar yesterday;/*from ww  w .jav a  2 s.co  m*/

    switch (limitActivePref) {
    case "ALLOW_CURRENT":
        return (date.compareTo(today) == 0);
    case "ALLOW_CURRENT_AND_NEXT_DAY":
        yesterday = (Calendar) today.clone();
        yesterday.add(Calendar.DATE, -1);
        return (date.compareTo(yesterday) >= 0);
    case "ALLOW_CURRENT_AND_NEXT_DAY_AND_WEEKEND":
        yesterday = (Calendar) today.clone();
        yesterday.add(Calendar.DATE, today.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY ? -2 : -1);
        return (date.compareTo(yesterday) >= 0);
    case "ALLOW_ALL":
    default:
        return true;
    }
}

From source file:Main.java

public static LinkedHashMap<String, Integer> getDateMap(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*  w w w  .  j  a  va  2 s.  c o m*/
    LinkedHashMap<String, Integer> datemap = new LinkedHashMap<String, Integer>();
    datemap.put("year", cal.get(Calendar.YEAR));
    datemap.put("month", cal.get(Calendar.MONTH));
    datemap.put("day", cal.get(Calendar.DAY_OF_MONTH));
    datemap.put("hour", cal.get(Calendar.HOUR_OF_DAY));
    datemap.put("minute", cal.get(Calendar.MINUTE));
    datemap.put("second", cal.get(Calendar.SECOND));
    datemap.put("millisecond", cal.get(Calendar.MILLISECOND));

    return datemap;

}

From source file:Main.java

public static String getTime(long time) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(time);/*from ww w .j  av  a2  s.c  om*/
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    String times = "";
    if (minute < 10) {
        times = "0" + minute;
    } else {
        times = "" + minute;
    }
    if (second < 10) {
        times += ":0" + second;
    } else {
        times += ":" + second;
    }
    return times;
}

From source file:Main.java

/**
 * yyyyMMddHHmmss/*  w  w w . j a v a  2s.  c o  m*/
 */
public static String getFormatTime3(Calendar c) {
    DecimalFormat df = new DecimalFormat("00");
    String strFileName = c.get(Calendar.YEAR) + df.format((c.get(Calendar.MONTH) + 1))
            + df.format(c.get(Calendar.DAY_OF_MONTH)) + df.format(c.get(Calendar.HOUR_OF_DAY))
            + df.format(c.get(Calendar.MINUTE)) + df.format(c.get(Calendar.SECOND));

    return strFileName;
}

From source file:Main.java

public static void addCalendarSecond(Calendar cal, int seconds) {
    cal.add(Calendar.SECOND, seconds);
}

From source file:Main.java

public static String getCurrentTimeStamp() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":"
            + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}