Example usage for java.util Calendar YEAR

List of usage examples for java.util Calendar YEAR

Introduction

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

Prototype

int YEAR

To view the source code for java.util Calendar YEAR.

Click Source Link

Document

Field number for get and set indicating the year.

Usage

From source file:Main.java

public static String getDateTime(Calendar calendar) {
    int year = calendar.get(Calendar.YEAR);
    //  if (year>3900) year-=1900;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    //Date date = new Date();
    return dateFormat
            .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)));
}

From source file:Main.java

public static String createCCPFileName() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());

    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    return y + "-" + m + "-" + d + "-" + hour + "-" + minute + "-" + second;
}

From source file:Main.java

public static Date addYear(Date date, int step) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from  w  w w.j ava 2s.co  m*/
    calendar.add(Calendar.YEAR, step);
    return calendar.getTime();
}

From source file:Main.java

public static String get_date() {
    int mYear;/*from  w  w w .ja  v  a2 s  . c o m*/
    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 String getDateString(long millitm) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millitm);/*w  w w.jav a  2s  .c o  m*/
    return (setZeroPad(cal.get(Calendar.YEAR)) + "/" + setZeroPad(cal.get(Calendar.MONTH)) + "/"
            + setZeroPad(cal.get(Calendar.DATE)) + " " + setZeroPad(cal.get(Calendar.HOUR_OF_DAY)) + ":"
            + setZeroPad(cal.get(Calendar.MINUTE)) + ":" + setZeroPad(cal.get(Calendar.SECOND)));
}

From source file:Main.java

public static int getYear(long date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);//from   w w  w.j  a  v  a2  s  . co m
    return c.get(Calendar.YEAR);
}

From source file:Main.java

public static String getDateTimeString(Calendar calendar) {
    int year = calendar.get(Calendar.YEAR);
    //  if (year>3900) year-=1900;
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault());
    //Date date = new Date();
    return dateFormat
            .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)));
}

From source file:Main.java

public static List<String> getAniosConsulta() {
    Calendar c = Calendar.getInstance();
    int anio = c.get(Calendar.YEAR);

    List<String> anios = new LinkedList<String>();
    int amount = anio + 6;

    for (int i = anio; i < amount; i++) {
        anios.add("" + anio--);
    }//from  w  w  w.  j  av a2s  .  c  o  m

    return anios;
}

From source file:Main.java

public static String toYYYYMMDD(Calendar source) {
    if (source == null) {
        return "Can't toYYYYMMDDHHMMSS source null";
    }//from w  w  w. j a v  a2s  .com
    int YYYY = source.get(Calendar.YEAR);
    int MM = source.get(Calendar.MONTH);
    int DD = source.get(Calendar.DAY_OF_MONTH);

    return YYYY + "-" + MM + "-" + DD;
}

From source file:Main.java

public static int[] getWeekSunday(int year, int month, int day, int pervious) {
    int[] time = new int[3];
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.add(Calendar.DAY_OF_MONTH, pervious);
    time[0] = c.get(Calendar.YEAR);
    time[1] = c.get(Calendar.MONTH) + 1;
    time[2] = c.get(Calendar.DAY_OF_MONTH);
    return time;//  w w w  .  ja v  a2 s .  co  m

}