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 long getTimesMonthNextStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, 24);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static void timeStamp(String tag) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    System.out.println("time stamp - " + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND)
            + ":" + calendar.get(Calendar.MILLISECOND) + " -- " + tag);
}

From source file:Main.java

public static int getCurrentDayOfMonth() {
    Calendar calendar = Calendar.getInstance();
    int currDay = calendar.get(Calendar.DAY_OF_MONTH);
    return currDay;
}

From source file:Main.java

public static int getDayOfMonth(int offset) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, offset);
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long getSmallHourTimestamp() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR, 0);//w  w w .j av  a 2 s .  c  o  m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

private static long getYesterdayZeroTime() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, -24);
    cal.set(Calendar.SECOND, 0);//w  w w.jav  a2s. co  m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

private static long getTimeInMillis() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 21);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static String getCurrentDateString() {
    Calendar date = Calendar.getInstance();
    int day = date.get(Calendar.DATE);
    int month = (date.get(Calendar.MONTH)) + 1;
    int year = date.get(Calendar.YEAR);
    String dateString = month + "-" + day + "-" + year;
    return dateString;
}

From source file:Main.java

public static Calendar getFirstDayOfWeek() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from  w w w  . ja  va  2s  .  c o  m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
}

From source file:Main.java

public static Calendar getTodayAt(int hours) {
    Calendar today = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hours);
    return calendar;
}