Example usage for java.util Date getYear

List of usage examples for java.util Date getYear

Introduction

In this page you can find the example usage for java.util Date getYear.

Prototype

@Deprecated
public int getYear() 

Source Link

Document

Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Usage

From source file:Main.java

public static String date2str(Date date) {
    if (date == null)
        return null;

    return date2str(date.getYear() + 1900, date.getMonth() + 1, date.getDate(), date.getHours(),
            date.getMinutes());//from   w ww.j  a  v a  2 s . com
}

From source file:Main.java

public static boolean isSameDay(Date d1, Date d2) {
    return d1.getDay() == d2.getDay() && d1.getMonth() == d2.getMonth() && d1.getYear() == d2.getYear();
}

From source file:Main.java

/**
 * Get the long representation of the beginning of the current date
 * @return current date in system time/*www  .j a v a  2s .  com*/
 */
public static long getCurrentDateStartLong() {
    final Date currentDate = new Date(System.currentTimeMillis());
    final Date currentDateBeginning = new Date(currentDate.getYear(), currentDate.getMonth(),
            currentDate.getDate());

    return currentDateBeginning.getTime();
}

From source file:Main.java

public static String formatDate(Date d) {
    // TODO let user pick date format preferences ( - or - consult system settings? )
    String s = (1900 + d.getYear()) + "/" + (d.getMonth() + 1) + "/" + (d.getDate());
    return s;/*from   w  ww. j  a v  a 2 s  .  c  om*/
}

From source file:Main.java

public static boolean isSameDay(Date date1, Date date2) {
    return date1.getDay() == date2.getDay() && date1.getMonth() == date2.getMonth()
            && date1.getYear() == date2.getYear();
}

From source file:Main.java

public static long getMonthTimeMilis(long l, int i) {
    Date date = new Date(l);
    GregorianCalendar gregoriancalendar = new GregorianCalendar();
    gregoriancalendar.set(date.getYear() + 1900, i, 1, 0, 0, 0);
    gregoriancalendar.set(14, 0);//  w w  w.java  2s.  c om
    return gregoriancalendar.getTimeInMillis();
}

From source file:Main.java

/**
 * @param period : today, this_week, this_month, this_year, none
 * @return a date filter string for making query. e.g. date >= 2013-1-1 for this_year
 * return null if period is none.//from   w  w  w .  jav a  2  s .c om
 */
@SuppressWarnings("deprecation")
public static String getDateFilterString(String period) {
    if (period == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH) + 1; // 1 - 12 
    int date = calendar.get(Calendar.DATE); // 1 - 31

    String dateFilterString = null;

    if (period.equalsIgnoreCase("today")) {
        dateFilterString = "date >= " + year + "-" + month + "-" + date;
    } else if (period.contains("week")) {
        int offset = calendar.get(Calendar.DAY_OF_WEEK) - calendar.getFirstDayOfWeek();
        long timeInMillis = calendar.getTimeInMillis() - offset * 24 * 60 * 60 * 1000;
        Date firstDay = new Date(timeInMillis);
        dateFilterString = "date >= " + (firstDay.getYear() + 1900) + "-" + firstDay.getMonth() + "-"
                + firstDay.getDate();
    } else if (period.contains("month")) {
        dateFilterString = "date >= " + year + "-" + month + "-1";
    } else if (period.contains("year")) {
        dateFilterString = "date >= " + year + "-1-1";
    }

    return dateFilterString;
}

From source file:Main.java

public static String formatDate(String strDate) {
    try {/*from  w w  w .ja v a 2s . c  o m*/
        // create SimpleDateFormat object with source string date format
        SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // parse the string into Date object
        Date date = sdfSource.parse(strDate);
        Date now = new Date();

        SimpleDateFormat sdfDestination;
        if (date.getYear() == now.getYear())
            sdfDestination = new SimpleDateFormat("dd MMM");
        else
            sdfDestination = new SimpleDateFormat("dd/MM/yyyy");

        return "Added on: " + sdfDestination.format(date);

    } catch (ParseException pe) {
        return "";
    }

}

From source file:irille.pub.svr.DateUtils.java

public static int subMonth(Date d1, Date d2) {
    int suby = d2.getYear() - d1.getYear();
    int rst = (suby + 1) * 12;
    rst = rst - d1.getMonth();//from   ww  w .j a  v a2s  .c  o  m
    rst = rst - (11 - d2.getMonth());
    return rst;
}

From source file:irille.pub.svr.DateUtils.java

public static Date getMonthOne(Date date) {
    return new Date(date.getYear(), date.getMonth(), 1);
}