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:GenerateWorkItems.java

/**
 * @param args/*from ww  w.  ja  va 2  s .  co m*/
 */
public static void main(String[] args) {
    initTorque();
    List issueTypes = issueTypeDAO.loadAll();
    List states = stateDAO.loadAll();
    List persons = PersonBL.loadPersons();
    List priorities = priorityDAO.loadAll();
    List severities = severityDAO.loadAll();
    Integer lastWorkItemID = null;
    for (int i = 0; i < numberOfItems; i++) {
        TWorkItemBean workItemBean = new TWorkItemBean();
        Integer randomProject = new Integer(1);// getRandomObjectIdFromList(projects);
        workItemBean.setListTypeID(getRandomObjectIdFromList(issueTypes));
        /*workItemBean.setProjectCategoryID(
              getRandomObjectIdFromList(subprojectDAO.loadByProject1(randomProject)));*/
        workItemBean.setStateID(getRandomObjectIdFromList(states));
        workItemBean.setOwnerID(getRandomObjectIdFromList(persons));
        workItemBean.setResponsibleID(getRandomObjectIdFromList(persons));
        /*workItemBean.setClassID(
              getRandomObjectIdFromList(classDAO.loadByProject1(randomProject)));*/
        /*workItemBean.setReleaseNoticedID(
              getRandomObjectIdFromList(ReleaseBL.loadNotClosedByProject(randomProject)));
        workItemBean.setReleaseScheduledID(
              getRandomObjectIdFromList(releaseDAO.loadNotClosedByProject(randomProject)));*/
        workItemBean.setPriorityID(getRandomObjectIdFromList(priorities));
        workItemBean.setSeverityID(getRandomObjectIdFromList(severities));
        workItemBean.setOriginatorID(getRandomObjectIdFromList(persons));
        workItemBean.setCreated(new Date());
        workItemBean.setLastEdit(new Date());
        workItemBean.setChangedByID(getRandomObjectIdFromList(persons));
        workItemBean.setSynopsis("Title" + i);
        workItemBean.setBuild("Build" + i);
        if (i % 2 == 1) {
            workItemBean.setSuperiorworkitem(lastWorkItemID);
        }
        Date date = new Date();
        workItemBean.setStartDate(new Date(date.getYear(), date.getMonth(), date.getDate()));
        workItemBean.setEndDate(new Date(date.getYear(), date.getMonth(), date.getDate() + 20));
        workItemBean.setDescription("Some descriptuion for item " + i);
        try {
            lastWorkItemID = workItemDAO.save(workItemBean);
        } catch (ItemPersisterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        TStateChangeBean stateChangeBean = new TStateChangeBean();
        stateChangeBean.setWorkItemID(workItemBean.getObjectID());
        stateChangeBean.setChangedToID(workItemBean.getStateID());
        stateChangeBean.setChangedByID(workItemBean.getChangedByID());
        stateChangeBean.setLastEdit(workItemBean.getLastEdit());
        stateChangeBean.setChangeDescription("Generated status change text for " + workItemBean.getObjectID());
        stateChangeDAO.save(stateChangeBean);
        System.out.println("Issue number " + workItemBean.getObjectID() + " created.");
    }

}

From source file:Main.java

/**
 * @param date/*from  w w  w .java2s  .co m*/
 *
 * @return
 */
public static String getFormatedDate(Date date) {
    return date.getYear() + "-" + date.getMonth() + "-" + date.getDay() + " - At " + date.getHours() + ":"
            + date.getMinutes();
}

From source file:Main.java

public static String date2calendarStr(Date date) {
    return date2calendarStr(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}

From source file:Main.java

public static int getMonthsDifference(Date date1, Date date2) {
    int m1 = date1.getYear() * 12 + date1.getMonth();
    int m2 = date2.getYear() * 12 + date2.getMonth();
    return m2 - m1 + 1;
}

From source file:Main.java

public static String format(Date d) {
    if (d == null || d.getTime() < ZERO_TIMESTAMP)
        return "";
    Date now = new Date();
    if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate())
        return FMT_TIME.format(d);
    else if (now.getYear() == d.getYear())
        return FMT_DATE.format(d);
    else/*w  w  w  . ja v  a2 s . co m*/
        return FMT_DATE2.format(d);
}

From source file:Main.java

public static String calculateAge(Context context, String date) {
    final String FACEBOOK = "MM/dd/yyyy";
    try {//from   w w  w  . j av a 2s .  c om
        SimpleDateFormat sf = new SimpleDateFormat(FACEBOOK, Locale.ENGLISH);
        sf.setLenient(true);
        Date birthDate = sf.parse(date);
        Date now = new Date();
        int age = now.getYear() - birthDate.getYear();
        birthDate.setHours(0);
        birthDate.setMinutes(0);
        birthDate.setSeconds(0);
        birthDate.setYear(now.getYear());
        if (birthDate.after(now)) {
            age -= 1;
        }
        return Integer.toString(age);

    } catch (Exception e) {
        Log.d("DEBUG", "exception in getTwitterDate:");
        e.printStackTrace();
        return "Unknown";
    }
}

From source file:Main.java

public static boolean isToday(Date dt) {
    Date today = new Date(System.currentTimeMillis());
    int year1 = today.getYear();
    int year2 = dt.getYear();
    int month1 = today.getMonth();
    int month2 = dt.getMonth();
    int day1 = today.getDate();
    int day2 = dt.getDate();
    if (year1 == year2 && month1 == month2 && day1 == day2) {
        return true;
    } else {//ww  w . j a  v  a2s . c  o  m
        return false;
    }
}

From source file:Main.java

public static int milli2int(long milli) {
    Date date = new Date(milli);
    int total = 0;
    int year = date.getYear() - 112;
    int month = date.getMonth() + 1;
    int day = date.getDate();
    int hour = date.getHours();
    int minute = date.getMinutes();
    int sec = date.getSeconds();
    total = year << 26;/*  w  w  w .j a va 2s  .  c o m*/
    total |= month << 22;
    total |= day << 17;
    total |= hour << 12;
    total |= minute << 6;
    total |= sec;
    return total;
}

From source file:common.util.DateUtil.java

public static boolean isCurrentYear(Integer year) {
    Date today = new Date();

    return today.getYear() + 1900 == year;
}

From source file:Main.java

/**
 * Convert a Date object in a string representing the date at readable style.
 *//*from   w  w w  .  j  a va 2 s . co  m*/
public static String dateToReadableString(Date date) {
    if (date == null)
        return "";
    else
        return ("" + (date.getYear() + 1900) + "/" + (date.getMonth() + 1) + "/" + date.getDate());
}