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 GetYear(boolean lastTwoDigitOnly) {
    Calendar now = Calendar.getInstance();
    if (!lastTwoDigitOnly)
        return now.get(Calendar.YEAR);
    else//  w w w .  j ava 2  s .c o m
        return Integer.parseInt(String.valueOf(now.get(Calendar.YEAR)).substring(2, 4));
}

From source file:Main.java

public static int getHourOfDay() {
    Calendar cal = Calendar.getInstance();
    Date date = cal.getTime();
    return date.getHours();
}

From source file:Main.java

private static Calendar add(long time, int val, int field) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(time);//www.  ja  v a  2  s . c o  m
    c.add(field, val);
    return c;
}

From source file:Main.java

public static Calendar getCurrentDateWithoutTime() {
    Calendar cal = Calendar.getInstance(); // locale-specific
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from   w w w . ja va2  s  .com*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
}

From source file:Main.java

public static String getSecond() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    int second = c.get(Calendar.SECOND);
    return Integer.toString(second);
}

From source file:Main.java

public static Calendar copyFromNow(Calendar aoCalendar) {
    aoCalendar.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
    return aoCalendar;
}

From source file:Main.java

public static Calendar getTimeAfterInSecs(int secs) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.SECOND, secs);
    return calendar;
}

From source file:Main.java

public static Calendar getNowCalendar(int afterDay) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, afterDay);
    return calendar;
}

From source file:Main.java

public static String millisToDate(long currentTime) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    return calendar.get(Calendar.HOUR) + ":" + calendar.get(Calendar.MINUTE) + ":"
            + calendar.get(Calendar.SECOND) + " " + (calendar.get(Calendar.AM_PM) == 0 ? "AM" : "PM");
}

From source file:Main.java

public static Calendar getBeginOfDate(long time) {
    Calendar ret = Calendar.getInstance();
    ret.setTimeInMillis(time);/*from   ww w .j av a  2  s  . c om*/
    ret.set(Calendar.HOUR_OF_DAY, 0);
    ret.set(Calendar.MINUTE, 0);
    ret.set(Calendar.SECOND, 0);
    ret.set(Calendar.MILLISECOND, 0);

    return ret;
}