Example usage for java.util Calendar getInstance

List of usage examples for java.util Calendar getInstance

Introduction

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

Prototype

public static Calendar getInstance() 

Source Link

Document

Gets a calendar using the default time zone and locale.

Usage

From source file:Main.java

public static int getWeekFromDay(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();//from www  .  j  av  a2s  .  c  om
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    return calendar.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

private static Date get8Hours10MinsAgo() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.HOUR, -8);
    calendar.add(Calendar.MINUTE, -10);

    return calendar.getTime();
}

From source file:Main.java

public static String getCurrentYear() {
    Calendar calendar = Calendar.getInstance();
    return Integer.toString(calendar.get(Calendar.YEAR));
}

From source file:Main.java

public static Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   w w  w  . j a v  a2 s  . c  om*/
    cal.add(Calendar.DATE, days); //minus number would decrement the days
    return cal.getTime();
}

From source file:Main.java

public static long startOfTodDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date date = calendar.getTime();
    return date.getTime();
}

From source file:Main.java

public static Date addFiveMinutes(Date date) {

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   w w  w .  j av  a2  s  .c  o m*/
    cal.add(Calendar.MINUTE, 5);
    return cal.getTime();
}

From source file:Main.java

public static Calendar getTodayAt(int hours, int minutes) {
    Calendar today = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.clear();//from  ww  w.  j ava 2  s .c  o  m

    int year = today.get(Calendar.YEAR);
    int month = today.get(Calendar.MONTH);
    //represents the day of the month
    int day = today.get(Calendar.DATE);
    cal.set(year, month, day, hours, minutes, 0);
    return cal;
}