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

private static long getTodayZeroTime() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);//from  ww  w  . java 2s  .c o  m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

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

From source file:Main.java

public static Calendar getCurrentDateTime() {
    Calendar calendar = Calendar.getInstance();
    return calendar;
}

From source file:Main.java

public static long firstOfTheMonth9am() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_MONTH, 1);
    c.set(Calendar.HOUR_OF_DAY, 9);
    c.set(Calendar.MINUTE, 0);//from w  w w . j a  v  a 2s.  c o  m
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:Main.java

public static int getDayOfMonth(int y, int m) {
    Calendar cal = Calendar.getInstance();
    cal.set(y, m - 1, 1);/*ww  w . j  a v a  2  s.c  o m*/
    int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
    return dateOfMonth;
}

From source file:Main.java

public static int getDayOfMaonth(int y, int m) {
    Calendar cal = Calendar.getInstance();
    cal.set(y, m - 1, 1);/*w  w  w.  ja  v  a2s .  c o  m*/
    int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
    return dateOfMonth;
}

From source file:Main.java

public static Calendar todaysCalendar() {
    Calendar now = Calendar.getInstance();
    return createNewCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH));
}

From source file:Main.java

public static boolean isWorkTime() {
    Calendar calendar = Calendar.getInstance();
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    if (hour < 9 || hour > 19) {
        return false;
    }/*from w ww .ja  v a 2  s  . c om*/

    return true;
}

From source file:Main.java

public static int getMonthOfMonth(int y, int m) {
    Calendar cal = Calendar.getInstance();
    cal.set(y, m - 1, 1);/* ww w.j a v  a  2  s.  com*/
    int dateOfMonth = cal.get(Calendar.MONTH);
    return dateOfMonth + 1;
}

From source file:Main.java

public static String getDateTimeString(long time) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(time);/*  www  .j  a  va 2  s  . c o m*/
    return c.getTime().toString();
}