Example usage for java.util Date getDate

List of usage examples for java.util Date getDate

Introduction

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

Prototype

@Deprecated
public int getDate() 

Source Link

Document

Returns the day of the month represented by this Date object.

Usage

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

public static Date getDateSub(Date date, int sub) {
    return new Date(date.getYear(), date.getMonth(), date.getDate() - sub);
}

From source file:common.util.DateUtil.java

public static String getWeekShortLabel(Date date, String lang) {
    System.out.println("getWeekShortLabel date = " + date);
    return date == null ? "" : getMonthShort(lang)[date.getMonth()] + " " + date.getDate();
}

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 {/*from   w  w  w  .  ja  v  a  2s .  c o m*/
        return false;
    }
}

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./*w  w w . j  a va 2 s .  co  m*/
 */
@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

static public void appendDateNode(Document owner, Element appendElement, String name, Date date) {
    Element dateElem = owner.createElement(name);
    appendElement.appendChild(dateElem);
    appendSingleValElement(owner, dateElem, "month", Integer.toString(date.getMonth() + 1));
    appendSingleValElement(owner, dateElem, "day", Integer.toString(date.getDate()));
    appendSingleValElement(owner, dateElem, "year", Integer.toString(date.getYear() + 1900));
    appendSingleValElement(owner, dateElem, "hour", Integer.toString(date.getHours()));
    appendSingleValElement(owner, dateElem, "minute", Integer.toString(date.getMinutes()));
    appendSingleValElement(owner, dateElem, "second", Integer.toString(date.getSeconds()));
}

From source file:Main.java

public static String getXMLDateString() {
    Date date = new Date();
    // YYYY-MM-DDThh:mm:ss

    // Must be a simpler way to do this....
    String xmlDateFormat = "" + (date.getYear() + 1900);
    int month = (date.getMonth() + 1);
    String monthStr = fillZero(month);
    String dateStr = fillZero(date.getDate());
    xmlDateFormat = xmlDateFormat + "-" + monthStr;
    xmlDateFormat = xmlDateFormat + "-" + dateStr;
    xmlDateFormat = xmlDateFormat + "T" + fillZero(date.getHours());
    xmlDateFormat = xmlDateFormat + ":" + fillZero(date.getMinutes());
    xmlDateFormat = xmlDateFormat + ":" + fillZero(date.getSeconds());

    return (xmlDateFormat);
}

From source file:org.alfresco.error.AlfrescoRuntimeException.java

/**
 * Generate an error log number - based on MMDDXXXX - where M is month,
 * D is day and X is an atomic integer count.
 * /*from w  w  w  .ja va  2  s.c o m*/
 * @param message       Message to prepend the error log number to 
 * 
 * @return message with error log number prefix
 */
private static String buildErrorLogNumber(String message) {
    // ensure message is not null
    if (message == null) {
        message = "";
    }

    Date today = new Date();
    StringBuilder buf = new StringBuilder(message.length() + 10);
    padInt(buf, today.getMonth(), 2);
    padInt(buf, today.getDate(), 2);
    padInt(buf, errorCounter.getAndIncrement(), 4);
    buf.append(MESSAGE_DELIMITER);
    buf.append(message);
    return buf.toString();
}

From source file:org.dms.sys.error.AlfrescoRuntimeException.java

/**
 * Generate an error log number - based on MMDDXXXX - where M is month,
 * D is day and X is an atomic integer count.
 * //from ww w  .j  av a  2  s . co  m
 * @param message       Message to prepend the error log number to 
 * 
 * @return message with error log number prefix
 */
private static String buildErrorLogNumber(String message) {
    // ensure message is not null
    if (message == null) {
        message = "";
    }

    Date today = new Date();
    StringBuilder buf = new StringBuilder(message.length() + 10);
    padInt(buf, today.getMonth(), 2);
    padInt(buf, today.getDate(), 2);
    padInt(buf, errorCounter.getAndIncrement(), 4);
    buf.append(' ');
    buf.append(message);
    return buf.toString();
}

From source file:Main.java

public static int compareDates(java.util.Date startDate, java.util.Date endDate) {
    int interval = 0;

    calendarStartDate = Calendar.getInstance();
    calendarStartDate.set(Calendar.YEAR, startDate.getYear());
    calendarStartDate.set(Calendar.MONTH, startDate.getMonth());
    calendarStartDate.set(Calendar.DAY_OF_MONTH, startDate.getDate());

    calendarEndDate.set(Calendar.YEAR, endDate.getYear());
    calendarEndDate.set(Calendar.MONTH, endDate.getMonth());
    calendarEndDate.set(Calendar.DAY_OF_MONTH, endDate.getDate());

    long diff = calendarEndDate.getTimeInMillis() - calendarStartDate.getTimeInMillis();
    interval = (int) (diff / (24 * 60 * 60 * 1000) + 1); // plus one day

    return interval;
}

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   w  w w.  ja v  a 2  s.  com*/

    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();
}