Example usage for java.util Calendar get

List of usage examples for java.util Calendar get

Introduction

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

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

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 boolean IsItTheWeekend() {
    Calendar calendarToday = Calendar.getInstance();

    if (calendarToday.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
            || calendarToday.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        //TODO: //Change back to true, set to false to test information on the weekend
        return true;
    } else {/*from w  w w  . j  av  a 2s  .  c o m*/
        return false;
    }

}

From source file:Main.java

public static int getDayOfWeek(Calendar c, boolean startOnSunday) {
    return getConvertedDayOfWeek(c.get(Calendar.DAY_OF_WEEK), startOnSunday);
}

From source file:Main.java

public static String get_date() {
    int mYear;/* w  w  w  .j  ava2  s .  c  om*/
    int mMonth;
    int mDay;

    final Calendar c = Calendar.getInstance();

    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH) + 1;
    mDay = c.get(Calendar.DAY_OF_MONTH);

    String result = String.format("%04d-%02d-%02d", mYear, mMonth, mDay);
    return result;
}

From source file:Main.java

public static int getMonthFromDate(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from   w  w  w.java  2  s  . c o  m
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static int getYearFromDate(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//www  . j av  a 2  s .  com
    return c.get(Calendar.YEAR);
}

From source file:Main.java

public static int getMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*from  w ww  . jav  a 2s .c o m*/
    return c.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static String getDateForFile() {
    Calendar currentTime = Calendar.getInstance();
    int month = currentTime.get(2);
    int date = currentTime.get(5);
    int year = currentTime.get(1);
    int hour = currentTime.get(11);
    int minute = currentTime.get(12);
    int second = currentTime.get(13);
    String result = year + "." + month + "." + date + "/" + hour + ":" + minute + ":" + second;
    return result;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String getCurrentTime() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
    String time = formatter.format(new Date());
    Calendar c = Calendar.getInstance();
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek == 1)
        time += ("07");
    else/*from  w  ww.  j  a  va 2s  .  c  o  m*/
        time += ("0" + (dayOfWeek - 1));
    return time;
}

From source file:Main.java

public static String formatCalendar(Calendar calendar) {
    if (calendar != null) {
        return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH);
    } else {//from   w ww .  j a v a  2s  .co  m
        return null;
    }
}