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:controllers.CNBCProxy.java

private static String CalculateDateFormat(long millis) {
    // Set helping arrays
    String[] monthArr = new String[12];
    String[] dayArr = new String[7];

    // Set month names
    monthArr[0] = "January";
    monthArr[1] = "February";
    monthArr[2] = "March";
    monthArr[3] = "April";
    monthArr[4] = "May";
    monthArr[5] = "June";
    monthArr[6] = "July";
    monthArr[7] = "August";
    monthArr[8] = "September";
    monthArr[9] = "October";
    monthArr[10] = "November";
    monthArr[11] = "December";

    // Set day names
    dayArr[0] = "Sunday";
    dayArr[1] = "Monday";
    dayArr[2] = "Tuesday";
    dayArr[3] = "Wednesday";
    dayArr[4] = "Thursday";
    dayArr[5] = "Friday";
    dayArr[6] = "Saturday";

    /** Create Date object with random date, in order to calculate date of article like 
    the "setTime()" function in Javascript (date since January 1, 1970 00:00:00 gmt)
    **///from ww w . ja v  a 2  s  .c om

    Date dateObj = new Date(92, 1, 10);

    // Add long number to get article's date
    dateObj.setTime(millis);

    StringBuilder date = new StringBuilder();
    date.append(dayArr[dateObj.getDay()]).append(", ").append(Integer.toString(dateObj.getDate())).append(" ")
            .append(monthArr[dateObj.getMonth()]).append(" ").append(Integer.toString(dateObj.getYear() + 1900))
            .append(" "); // 1900 added to year(see getYear() method's documentation)

    String hours;
    String midnight;

    if (dateObj.getHours() > 12) {
        if (dateObj.getHours() - 12 < 10) {
            hours = "0" + Integer.toString(dateObj.getHours() - 12);
        } else {
            hours = Integer.toString(dateObj.getHours() - 12);
        }
        midnight = "PM";
    } else {
        if (dateObj.getHours() < 10) {
            hours = "0" + Integer.toString(dateObj.getHours());
        } else {
            hours = Integer.toString(dateObj.getHours());
        }
        midnight = "AM";
    }

    date.append(hours).append(":").append(Integer.toString(dateObj.getMinutes()))
            .append(" " + midnight + " ET");

    return date.toString();
}

From source file:DateUtil.java

/**
 * Checks the day, month and year are equal.
 *//*from w  w  w  .ja va  2  s  .c  o  m*/
public static boolean dateEquals(java.util.Date d1, java.util.Date d2) {
    if (d1 == null || d2 == null)
        return false;

    return d1.getDate() == d2.getDate() && d1.getMonth() == d2.getMonth() && d1.getYear() == d2.getYear();
}

From source file:DateUtil.java

/**
  * Checks the second, hour, month, day, month and year are equal.
  *//*from  w w  w  .j  a  v a2  s  .  co m*/
public static boolean dateTimeEquals(java.util.Date d1, java.util.Date d2) {
    if (d1 == null || d2 == null)
        return false;

    return d1.getDate() == d2.getDate() && d1.getMonth() == d2.getMonth() && d1.getYear() == d2.getYear()
            && d1.getHours() == d2.getHours() && d1.getMinutes() == d2.getMinutes()
            && d1.getSeconds() == d2.getSeconds();
}

From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java

/**
 * Auto generated method comment//  w w w  .j a v a  2  s . c  om
 * 
 * @return
 */
private static CategoryDataset createMonthDataset() {

    Date curDate = new Date();

    int numberOfRepetitions = curDate.getMonth() + 1;

    VCTModuleService vms = Context.getService(VCTModuleService.class);

    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    int month = 0;

    while (month < numberOfRepetitions) {
        double value = vms.getNumberOfClientByMonthAndYearOfRegistration(month + 1, curDate.getYear() + 1900);
        dataset.addValue(value, "year", VCTTracUtil.getMessage("vcttrac.month." + (month + 1), null));
        month += 1;
    }

    return dataset;

}

From source file:eionet.meta.exports.ods.Ods.java

/**
 * Returns date.// ww  w  . j a v  a 2  s . co m
 *
 * @param timestamp
 *            time stamp
 *
 * @return date as a string
 */
public static String getDate(long timestamp) {

    Date date = new Date(timestamp);
    String year = String.valueOf(1900 + date.getYear());
    String month = String.valueOf(date.getMonth() + 1);
    month = (month.length() < 2) ? ("0" + month) : month;
    String day = String.valueOf(date.getDate());
    day = (day.length() < 2) ? ("0" + day) : day;
    String hours = String.valueOf(date.getHours());
    hours = (hours.length() < 2) ? ("0" + hours) : hours;
    String minutes = String.valueOf(date.getMinutes());
    minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes;
    String seconds = String.valueOf(date.getSeconds());
    seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds;

    String time = year;
    time = time + "-" + month;
    time = time + "-" + day;
    time = time + "T" + hours;
    time = time + ":" + minutes;
    time = time + ":" + seconds;

    return time;
}

From source file:org.infoscoop.request.filter.rss.RssHandler.java

/**
 * Return the date whose form is "yyyy/MM/dd HH:mm:ss" -> obsolute
 * javascript Date :An argument form of the object instance.
 * Return the date whose form is "yyyy,MM,dd,HH,mm,ss".
 * /*  www . jav  a2  s.c  om*/
 * @param date
 * @return
 */
public static String getFullDate(Date date) {
    if (date == null) {
        return null;
    }

    try {
        //         return formatFullDate.format(date);
        return (date.getYear() + 1900) + "," + date.getMonth() + "," + date.getDate() + "," + date.getHours()
                + "," + date.getMinutes() + "," + date.getSeconds();
    } catch (IllegalArgumentException e1) {
        return null;
    }
}

From source file:it.scoppelletti.mobilepower.types.SimpleDate.java

/**
 * Restituisce la data rappresentata da una stringa in formato ISO 8601
 * ({@code yyyy-MM-dd}).//from   w  ww . ja  v a2  s.  com
 * 
 * @param  s Stringa.
 * @return   Data. Se la stringa {@code s} &egrave; nulla, restituisce la
 *           data nulla.
 * @see    #NIL
 * @see    #isEmpty
 */
public static SimpleDate fromISOString(String s) throws ParseException {
    Date value;
    SimpleDate date;
    SimpleDateFormat fmt;

    if (StringUtils.isBlank(s)) {
        return SimpleDate.NIL;
    }

    fmt = new SimpleDateFormat("yyyy-MM-dd");

    value = fmt.parse(s);
    date = new SimpleDate(1900 + value.getYear(), value.getMonth(), value.getDate());
    return date;
}

From source file:com.krawler.esp.handlers.basecampHandler.java

public static long getDiff(Date dt1, Date dt2) {
    Date dt3 = new Date(dt1.getYear(), dt1.getMonth(), dt1.getDate());
    Date dt4 = new Date(dt2.getYear(), dt2.getMonth(), dt2.getDate());

    long diff = (dt3.getTime() - dt4.getTime()) / (1000 * 60 * 60 * 24);
    return diff;/* ww w  .  j a  va2s .co m*/

}

From source file:org.rifidi.emulator.reader.llrp.report.LLRPReportController.java

/**
 * Gets the UTC Time.//from w  w w.  java  2  s  . c o  m
 * 
 * @param dateString
 * @param timeString
 * @return time in milliseconds
 */
@SuppressWarnings("deprecation")
private static long getUTCTimeInMillis(String dateString, String timeString) {

    /*
     * TODO: baindaid solution until radio saves and returns java date and
     * time objects
     */
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

    Date date, time = null;
    try {
        date = dateFormat.parse(dateString);
        time = timeFormat.parse(timeString);
    } catch (ParseException e) {
        logger.error("There was a problem converting the date or time string into a Date object");
        date = new Date();
        time = new Date();
    }

    GregorianCalendar gc = new GregorianCalendar(date.getYear(), date.getMonth(), date.getDate(),
            time.getHours(), time.getMinutes(), time.getSeconds());

    return gc.getTimeInMillis();
}

From source file:com.emental.mindraider.ui.outline.treetable.OutlineTreeInstance.java

/**
 * Get string to be rendered for creation time (today, 6 days, this year,
 * another year).// w ww.  ja  v a  2s . c o  m
 *
 * @param created
 * @return
 */
public static String getCreatedToRender(long created) {
    int type = CREATED;

    Date date = new Date(created);
    Date today = new Date(System.currentTimeMillis());
    SimpleDateFormat simpleDateFormat;

    /*
     * if (date.getYear() == today.getYear() && date.getMonth() ==
     * today.getMonth() && date.getDate() == today.getDate())
     */
    if (DateUtils.isSameDay(date, today)) {
        type = CREATED_TODAY;
    } else {
        if (System.currentTimeMillis() - created < SIX_DAYS) {
            type = CREATED_6_DAYS;
        } else {
            if (date.getYear() == today.getYear()) {
                type = CREATED_THIS_YEAR;
            }
        }
    }

    String bgColor = null, text = null;
    switch (type) {
    case CREATED:
        bgColor = "bbbbbb";
        simpleDateFormat = new SimpleDateFormat("yyyy");
        text = simpleDateFormat.format(date);
        break;
    case CREATED_6_DAYS:
        bgColor = "555555";
        simpleDateFormat = new SimpleDateFormat("EEE", new Locale("en", "US"));
        text = simpleDateFormat.format(date);
        break;
    case CREATED_THIS_YEAR:
        bgColor = "888888";
        simpleDateFormat = new SimpleDateFormat("MMM dd", new Locale("en", "US"));
        text = simpleDateFormat.format(date);
        break;
    case CREATED_TODAY:
        bgColor = "000000";
        simpleDateFormat = new SimpleDateFormat("HH:mm");
        text = simpleDateFormat.format(date);
        break;
    }

    // TODO colorize & transform according to the date

    // note that long timestamp is added to the HTML - it is convenient for parsing/sorting/processing
    return "<html><body bgColor='#" + bgColor + "'><font color='#ffffff'>&nbsp;&nbsp;" + text
            + "&nbsp;&nbsp;</font><span hidden='" + created + "'/></body></html>";
}