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:jp.classmethod.aws.petrucci.Tasks.java

@Scheduled(cron = "* * * * * *")
public void timeKeeper() {
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    logger.info(df.format(new Date()));
}

From source file:com.googlecode.flickrjandroid.interestingness.InterestingnessInterface.java

/**
 * /*from  ww w.java2 s  .  c  o m*/
 * @param date
 * @param extras
 * @param perPage
 * @param page
 * @return PhotoList
 * @throws FlickrException
 * @throws IOException
 * @throws JSONException 
 * @throws NoSuchAlgorithmException 
 * @throws InvalidKeyException 
 * @see com.googlecode.flickrjandroid.photos.Extras
 */
public PhotoList getList(Date date, Set<String> extras, int perPage, int page)
        throws FlickrException, IOException, InvalidKeyException, NoSuchAlgorithmException, JSONException {
    String dateString = null;
    if (date != null) {
        DateFormat df = (DateFormat) DATE_FORMATS.get();
        dateString = df.format(date);
    }
    return getList(dateString, extras, perPage, page);
}

From source file:com.buaa.cfs.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.
 *
 * @param dateFormat date format to use//from  ww  w.  j  a va 2s. c  om
 * @param finishTime fnish time
 * @param startTime  start time
 *
 * @return formatted value.
 */
public static String getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime) {
    StringBuilder buf = new StringBuilder();
    if (0 != finishTime) {
        buf.append(dateFormat.format(new Date(finishTime)));
        if (0 != startTime) {
            buf.append(" (" + formatTimeDiff(finishTime, startTime) + ")");
        }
    }
    return buf.toString();
}

From source file:itdelatrisu.opsu.downloads.servers.BloodcatServer.java

/**
 * Returns a formatted date string from a raw date.
 * @param s the raw date string (e.g. "2015-09-30 09:39:04.536")
 * @return the formatted date, or the raw string if it could not be parsed
 *//*  w  w w . j  ava  2  s.  co  m*/
private String formatDate(String s) {
    try {
        // old format: "2015-05-14T23:38:47+09:00"
        // make string parseable by SimpleDateFormat
        //         int index = s.lastIndexOf(':');
        //         if (index == -1)
        //            return s;
        //         s = new StringBuilder(s).deleteCharAt(index).toString();

        DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //"yyyy-MM-dd'T'HH:mm:ssZ"
        Date d = f.parse(s);
        DateFormat fmt = new SimpleDateFormat("d MMM yyyy HH:mm:ss");
        return fmt.format(d);
    } catch (StringIndexOutOfBoundsException | ParseException e) {
        return s;
    }
}

From source file:jp.co.acroquest.endosnipe.web.explorer.controller.JvnFileDownloadController.java

/**
 * Jvn?/* w  w w.  ja  v  a 2  s  .c o m*/
 * @param logIds IDJSON
 * @param res ?
 * @throws Exception ????
 */
@RequestMapping(value = "/download", method = RequestMethod.POST)
public void download(@RequestParam(value = "logIds") final String logIds, final HttpServletResponse res)
        throws Exception {
    List<String> logIdStrList = JSON.decode(logIds);
    List<Long> logIdList = new ArrayList<Long>();
    for (String logIdStr : logIdStrList) {
        logIdList.add(Long.valueOf(logIdStr));
    }
    DateFormat dateFormat = new SimpleDateFormat(FILE_DATE_FORMAT);
    String fileName = "jvn_" + dateFormat.format(new Date()) + ".zip";
    res.setContentType("application/zip;charset=UTF8");
    res.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    res.setHeader("Content-Transfer-Encoding", "binary");

    OutputStream os = res.getOutputStream();
    this.jvnFileDownloadService_.writeFile(os, logIdList);
}

From source file:com.gisgraphy.util.TimestampConverter.java

/**
 * Convert from a java.util.Date to a String
 * //from  w  w w  .  ja  v  a 2s .c om
 * @param type
 *                java.lang.String
 * @param value
 *                the date instance
 * @return string version of date using default date pattern
 */
@SuppressWarnings("unchecked")
@Override
protected Object convertToString(Class type, Object value) {
    DateFormat df = new SimpleDateFormat(TS_FORMAT);
    if (value instanceof Date) {
        try {
            return df.format(value);
        } catch (Exception e) {
            throw new ConversionException("Error converting Timestamp to String");
        }
    }

    return value.toString();
}

From source file:com.haulmont.chile.core.datatypes.impl.DateDatatype.java

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }/*w  ww. ja  v  a  2s .  co  m*/

    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return format(value);
    }

    DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat());
    return format.format(value);
}

From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java

/**
 * Parse date with pattern yyyyMMddHHmm. Pattern is used in get file command response XML.
 *
 * @param file input file./*w w  w. ja  va 2 s  .c om*/
 * @return parsed file modification date.
 */
public static String parseLastModifDate(final File file) {
    Date date = new Date(file.lastModified());
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
    return dateFormat.format(date);
}

From source file:com.mscorp.automation.seleniumCoreUtils.TakeScreenshot.java

public void takeScreenshot() {
    screenshotPath = (getProperty("screenshot-path") != null) ? getProperty("screenshot-path") : screenshotPath;
    DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_a");
    Date date = new Date();
    String date_time = dateFormat.format(date);
    File file = new File(System.getProperty("user.dir") + File.separator + screenshotPath + File.separator
            + this.testname + File.separator + date_time);
    boolean exists = file.exists();
    if (!exists) {
        new File(System.getProperty("user.dir") + File.separator + screenshotPath + File.separator
                + this.testname + File.separator + date_time).mkdir();
    }// ww w . j a v a 2s  .com

    File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
        String saveImgFile = System.getProperty("user.dir") + File.separator + screenshotPath + File.separator
                + this.testname + File.separator + date_time + File.separator + "screenshot.png";
        System.out.println("Save Image File Path : " + saveImgFile);
        FileUtils.copyFile(scrFile, new File(saveImgFile));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public void run() {
    Date d = new Date();
    DateFormat df = new SimpleDateFormat("HH:mm:ss:SSS");
    long startTime = System.currentTimeMillis();
    d.setTime(startTime);//from w  w w  . ja v a 2 s.com
    System.out.println("Starting task " + id + " at " + df.format(d));
    fib(n);
    long endTime = System.currentTimeMillis();
    d.setTime(endTime);
    System.out.println(
            "Ending task " + id + " at " + df.format(d) + " after " + (endTime - startTime) + " milliseconds");
}