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 toStandardFormat(String str) {
    String[] s = str.split("-");
    String tailStr;//from w w  w .  j a  v a  2s .com
    if (s[1].length() == 1) {
        tailStr = "0" + s[1] + s[2];
    } else {

        tailStr = s[1] + s[2];
    }

    String headStr = Calendar.getInstance().get(Calendar.YEAR) + "";
    return headStr + tailStr;
}

From source file:Main.java

@SuppressLint("DefaultLocale")
public static void SaveLastWallpaperDate(Context context, Calendar dateTime) {
    int year = dateTime.get(Calendar.YEAR);
    int month = dateTime.get(Calendar.MONTH);
    int date = dateTime.get(Calendar.DATE);

    String dateTimeToString = String.format("%d/%d/%d", year, month, date);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    preferences.edit().putString("wallpaper_date", dateTimeToString).commit();
}

From source file:Main.java

public static long getCountDownDays(int dayMonth, int month, int year) {

    Calendar thatDay = Calendar.getInstance();
    thatDay.set(Calendar.DAY_OF_MONTH, dayMonth);
    thatDay.set(Calendar.MONTH, month - 1); // 0-11 so 1 less
    thatDay.set(Calendar.YEAR, year);

    Calendar today = Calendar.getInstance();
    long diff = thatDay.getTimeInMillis() - today.getTimeInMillis();

    return diff / (24 * 60 * 60 * 1000);

}

From source file:Main.java

/**
 * Returns two days old date from the current date. This is used with forusquare web service to get the data
 * according to date./*from   w w w.j a v  a2  s  .c o m*/
 * 
 * @return date in string.
 */
public static String getTwoDaysOldDate() {

    int yyyy = Calendar.getInstance().get(Calendar.YEAR);
    int MM = Calendar.getInstance().get(Calendar.MONTH) + 1;
    int dd = Calendar.getInstance().get(Calendar.DATE) - 2;
    Calendar cal = Calendar.getInstance();
    if (dd < 1) {
        MM = MM - 1;
        if (MM < 0) {
            MM = 0;
        }
    }

    if (MM < 0) {
        yyyy = yyyy - 1;
    }
    cal.set(yyyy, MM, 1);
    dd = cal.getActualMaximum(Calendar.DATE) - dd;
    String oldDate = String.format("%04d%02d%02d", yyyy, MM, dd);

    return oldDate;
}

From source file:Main.java

public static boolean isSameDay(long timestamp1, long timestamp2) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();

    cal1.setTime(new Date(timestamp1));
    cal2.setTime(new Date(timestamp2));

    boolean sameYear = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR);
    boolean sameDay = cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);

    return sameYear && sameDay;
}

From source file:Main.java

public static String dateGraphLabelParser(long epoch) {
    Date date = new Date(epoch);
    Calendar cal = Calendar.getInstance();

    cal.setTime(date);//from  w ww.  j a  v a2  s.  co m

    return String.format("%d/%d/%d", cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH),
            cal.get(Calendar.YEAR));
}

From source file:Main.java

/**
 * Returns a date formatted in ANSI SQL.
 *
 * @param date the Date.//from   w w  w  .jav a 2s . c  o m
 * @return a date String.
 */
public static String getSqlDateString(Date date) {
    Calendar cal = Calendar.getInstance();

    cal.setTime(date);

    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);

    String yearString = String.valueOf(year);
    String monthString = month < 10 ? "0" + month : String.valueOf(month);
    String dayString = day < 10 ? "0" + day : String.valueOf(day);

    return yearString + "-" + monthString + "-" + dayString;
}

From source file:Main.java

public static boolean isSixMonthsAgo(Calendar c1, Calendar c2) {
    int year1 = c1.get(Calendar.YEAR);
    int month1 = c1.get(Calendar.MONTH);

    int year2 = c2.get(Calendar.YEAR);
    int month2 = c2.get(Calendar.MONTH);

    if ((year1 * 12 + month1) - (year2 * 12 + month2) > 6)
        return true;
    return false;
}

From source file:Main.java

/**
 * Returns <tt>true</tt> if the two given calendars are dated on the same year.
 * @param one The one calendar./*  w w w . j  av a  2s  .  c  o  m*/
 * @param two The other calendar.
 * @return True if the two given calendars are dated on the same year.
 */
public static boolean sameYear(Calendar one, Calendar two) {
    return one.get(Calendar.YEAR) == two.get(Calendar.YEAR);
}

From source file:MainClass.java

public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second,
        int millisecond) {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DATE, day);/*from   w ww  . ja  v  a 2s . c  o  m*/
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);

    // now convert GregorianCalendar object to Timestamp object
    return new Timestamp(cal.getTimeInMillis());
}