Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

In this page you can find the example usage for java.text DateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:datavis.Gui.java

/** 
 * Returns a new PSAWWB data list containing data pulled from TCOON's website
 * @param station The station number, e.g., 33 for Port Lavaca
 * @param interval The number of seconds between data samples, e.g., 86400
 * @param start Date range start date/*from  w  w  w .j  a v  a2 s .  c o  m*/
 * @param end Date range end date. Defaults to 1 year if null
 * @return A fresh DataList
 */
public static DataList_PWL_SURGE_ATP_WTP_WSD_BPR getDataFromServer(int station, int interval, Date start,
        Date end) throws UnsupportedEncodingException {
    String dateString = new String(), pattern = new String("%25Y%25j%2B%25H%25M");
    DateFormat format = new SimpleDateFormat("MM.dd.yyyy");
    File temp = null;
    URL url;

    if (interval % 360 != 0 || interval < 360)
        interval = 0; // default to monthly
    if (interval >= 86400)
        pattern = "%25m-%25d-%25Y";
    if (start == null || end == null)
        dateString = "now,-1y";
    else
        dateString = format.format(start) + "-" + format.format(end);
    try {
        temp = File.createTempFile("TCOON", null);
        temp.deleteOnExit();
        url = new URL(String.format(
                "http://lighthouse.tamucc.edu/pd?stnlist=%03d&serlist=pwl,surge,atp,wtp,wsd,bpr&when=%s&whentz=UTC0&-action=csv&unit=metric&elev=stnd&interval=%s&datefmt=%s&rm=0&na=0",
                station, dateString, interval > 0 ? String.valueOf(interval) : "monthly", pattern));
        Files.copy(url.openStream(), temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
    }

    return new DataList_PWL_SURGE_ATP_WTP_WSD_BPR(temp.getAbsolutePath());
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the day as an international formatted string corresponding to the
 * date code//from   w  w w  .j a  va 2s . c om
 * @return The day as a string
 * @param locale The locale used for display settings
 * @param strDate The date code
 */
public static String getDayLabel(String strDate, Locale locale) {
    Calendar calendar = new GregorianCalendar(locale);
    calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate));

    String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_DAY);
    DateFormat formatDate = new SimpleDateFormat(strFormat, locale);

    return formatDate.format(calendar.getTime());
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the day as an international formatted string corresponding to the
 * date code//w  w  w .j  a  va  2s . c o m
 * @return The day as a string
 * @param locale The locale used for display settings
 * @param strDate The date code
 */
public static String getWeekDayLabel(String strDate, Locale locale) {
    Calendar calendar = new GregorianCalendar(locale);
    calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate));

    String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_WEEK_DAY);
    DateFormat formatDate = new SimpleDateFormat(strFormat, locale);

    return formatDate.format(calendar.getTime());
}

From source file:com.aliyun.odps.utils.StringUtils.java

/**
 * Formats time in ms and appends difference (finishTime - startTime) as
 * returned by formatTimeDiff(). If finish time is 0, empty string is
 * returned, if start time is 0 then difference is not appended to return
 * value.//  w  ww  .  java  2s.c o m
 *
 * @param dateFormat
 *     date format to use
 * @param finishTime
 *     fnish time
 * @param startTime
 *     start time
 * @return formatted value.
 */
public static String getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime) {
    StringBuffer buf = new StringBuffer();
    if (0 != finishTime) {
        buf.append(dateFormat.format(new Date(finishTime)));
        if (0 != startTime) {
            buf.append(" (" + formatTimeDiff(finishTime, startTime) + ")");
        }
    }
    return buf.toString();
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the month as a formatted string corresponding to the date code
 * @return The month label//from ww w  .  j a v  a 2s  .c om
 * @param locale The locale used for display settings
 * @param strDate The date code
 */
public static String getMonthLabel(String strDate, Locale locale) {
    Calendar calendar = new GregorianCalendar();
    calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), 1);

    String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_MONTH);
    DateFormat formatDate = new SimpleDateFormat(strFormat, locale);
    String strLabel = formatDate.format(calendar.getTime());

    return strLabel;
}

From source file:com.joinsystem.goku.common.utils.DateUtil.java

/**
 * ?()</br>/*from   w ww  . j av a2  s  .  c o m*/
 * @return
 *      yyyyMMddHHmmss??
 */
public static String getOrderNum() {
    Date date = new Date();
    DateFormat df = new SimpleDateFormat(dtLong);
    return df.format(date);
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the Week as a formatted string corresponding to the date code
 * @return The week label//from  w  w  w .  j a v  a  2  s .co  m
 * @param locale The locale used for display settings
 * @param strDate The date code
 */
public static String getWeekLabel(String strDate, Locale locale) {
    Calendar calendar = new GregorianCalendar();
    Calendar calendarFirstDay = new GregorianCalendar();
    Calendar calendarLastDay = new GregorianCalendar();
    calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate));

    int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    if (nDayOfWeek == 1) {
        nDayOfWeek = 8;
    }

    calendarFirstDay = calendar;
    calendarFirstDay.add(Calendar.DATE, Calendar.MONDAY - nDayOfWeek);
    calendarLastDay = (GregorianCalendar) calendarFirstDay.clone();
    calendarLastDay.add(Calendar.DATE, 6);

    String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_DATE_OF_DAY);
    DateFormat formatDate = new SimpleDateFormat(strFormat, locale);
    String strLabelFirstDay = formatDate.format(calendarFirstDay.getTime());
    String strLabelLastDay = formatDate.format(calendarLastDay.getTime());
    calendarFirstDay.clear();
    calendarLastDay.clear();

    return strLabelFirstDay + "-" + strLabelLastDay;
}

From source file:de.perdian.commons.lang.conversion.impl.converters.DateToStringConverter.java

@Override
protected String convertUsingFormat(DateFormat format, Date source) {
    return source == null ? null : format.format(source);
}

From source file:com.agloco.util.StringUtil.java

private static String format(Date d, String format) {
    if (d == null)
        return "";
    DateFormat f = new SimpleDateFormat(format);
    return f.format(d);
}

From source file:ch.ralscha.extdirectspring_itest.TransactionalService.java

@ExtDirectMethod(group = "transactional")
@Transactional/*from  w w  w. ja v a 2  s  .  c  o  m*/
public String setDate(String id, @DateTimeFormat(pattern = "dd/MM/yyyy") Date date) {
    DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    return id + "," + dateFormat.format(date);
}