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

public static String previousDateString(String dateString) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

    Date myDate = dateFormat.parse(dateString);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(myDate);//from  www  .j  a  v a 2  s.c o m
    calendar.add(Calendar.DAY_OF_YEAR, -1);

    Date previousDate = calendar.getTime();
    String result = dateFormat.format(previousDate);

    return result;
}

From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java

/**
 * Trim hour-minute-second of date instance value to zero.
 * /*from   w  w  w  .j  a  v  a2 s  .  co m*/
 * @param value
 * @return
 */
public static Date trimHMSOfDate(Date value) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    try {
        return df.parse(df.format(value.getTime()));
    } catch (ParseException e) {
        throw new MyCollabException(e);
    }
}

From source file:com.gst.integrationtests.common.Utils.java

public static String convertDateToURLFormat(final Calendar dateToBeConvert) {
    DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy");
    dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
    return dateFormat.format(dateToBeConvert.getTime());
}

From source file:com.haulmont.timesheets.global.DateTimeUtils.java

private static Set<String> holidayAsSeparateStrings(Holiday holiday, Date startDate, Date endDate,
        String format) {//from  w w w .j  a v  a2 s  .  com
    Date start;
    Date end;
    if (holiday.getStartDate().getTime() >= startDate.getTime()) {
        start = holiday.getStartDate();
    } else {
        start = startDate;
    }
    if (holiday.getEndDate().getTime() <= endDate.getTime()) {
        end = holiday.getEndDate();
    } else {
        end = endDate;
    }

    if (start.equals(startDate) && end.equals(endDate)) {
        return Collections.emptySet();
    } else {
        Set<String> stringDates = new HashSet<>();
        DateFormat formatter = new SimpleDateFormat(format);
        while (start.getTime() <= end.getTime()) {
            stringDates.add(formatter.format(start));
            start = DateUtils.addDays(start, 1);
        }

        return stringDates;
    }
}

From source file:fr.univlorraine.mondossierweb.utils.Utils.java

/** formatage d'une date pour ne garder que jour, mois , annee*/
public static String formatDateToString(Date d) {
    if (d != null) {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        return dateFormat.format(d);
    } else {//from   ww  w.  j  a va  2s . c  o  m
        return null;
    }
}

From source file:Main.java

/**
 * Return date in specified format./*from ww  w  .java2  s.  c o m*/
 * @param  milliSeconds Date in milliseconds
 * @param  dateFormat Date format 
 * @return String representing date in specified format
 */
public static String getDate(long milliSeconds, String dateFormat) {
    // Create a DateFormatter object for displaying date in specified format.
    DateFormat formatter = new SimpleDateFormat(dateFormat);
    // Create a calendar object that will convert the date and time value in milliseconds to date. 
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:com.doculibre.constellio.stats.StatsCompiler.java

public static String format(Date date) {
    DateFormat dv = DateUtil.getThreadLocalDateFormat();
    return dv.format(date).replace("-", "");
}

From source file:Main.java

/**
 * getDateAsString/* www  .j  av a2 s  . c  om*/
 * Convert a date into a string
 *
 * @param date   the date
 * @param format the format in which to return the string
 * @return the new formatted date string
 */
public static String getDateAsString(Date date, String format, String timezone) {
    DateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
    if (timezone == null) {
        formatter.setTimeZone(TimeZone.getDefault());
    } else {
        formatter.setTimeZone(TimeZone.getTimeZone(timezone));
    }
    return formatter.format(date);
}

From source file:acromusashi.kafka.log.producer.util.StrftimeFormatMapper.java

/**
 * ??STRFTime??STRFTime??????//from   ww w.j a v  a  2s. c o  m
 * 
 * @param timeStr STRFTime??
 * @param strfFormatStr STRFTime
 * @param outputFormatStr 
 * @return ??
 * @throws ParseException 
 */
public static String convertStftToDateStr(String timeStr, String strfFormatStr, String outputFormatStr)
        throws ParseException {
    DateFormat strfFormat;

    // STRFTime????????Apache??
    if (StringUtils.isEmpty(strfFormatStr) == true) {
        strfFormat = new SimpleDateFormat(DEFAULT_STRFTIME, Locale.ENGLISH);

    } else {
        // STRFTime?DateFormat???
        strfFormat = StrftimeFormatMapper.convertStftToDateFormat(strfFormatStr);
    }

    // STRFTime???DateFormat??Date???
    Date logDate = strfFormat.parse(timeStr);

    // ?????
    DateFormat outputDateFormat = new SimpleDateFormat(outputFormatStr);
    String returnDate = outputDateFormat.format(logDate);
    return returnDate;
}

From source file:com.viettel.logistic.common.logs.KPILogger.java

public static void createLogsStartAction(String description) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
    Date date = new Date();
    Logger businessLog = Logger.getLogger("kpiLog");
    businessLog.error("START_ACTION|" + SYSTEM_DEFAULT + "|" + dateFormat.format(date) + "|" + description);
}