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:br.eti.fernandoribeiro.jenkins.cloudserverpro.SignatureClientFilter.java

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;/*from   w  ww . j  a  v  a2 s . c o  m*/

    try {
        logger.println("Adding signature to request");

        final Map<String, List<Object>> headers = request.getHeaders();

        final List<Object> value = new ArrayList<Object>();

        final DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");

        final String timestamp = formatter.format(date);

        final Hex encoder = new Hex();

        final MessageDigest digester = MessageDigest.getInstance("SHA1");

        value.add(login + ":" + timestamp + ":" + Base64.encodeBase64String(
                encoder.encode(digester.digest((login + contentLength + timestamp + secretKey).getBytes()))));

        headers.put(HeaderNames.SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
        logger.println("Can't handle request");
    }

    return result;
}

From source file:br.eti.fernandoribeiro.maven.cloudserverpro.SignatureClientFilter.java

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;//www.j  a v a 2s .com

    try {
        log.info("Adding signature to request");

        final Map<String, List<Object>> headers = request.getHeaders();

        final List<Object> value = new ArrayList<Object>();

        final DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");

        final String timestamp = formatter.format(date);

        final Hex encoder = new Hex();

        final MessageDigest digester = MessageDigest.getInstance("SHA1");

        value.add(login + ":" + timestamp + ":" + Base64.encodeBase64String(
                encoder.encode(digester.digest((login + contentLength + timestamp + secretKey).getBytes()))));

        headers.put(HeaderNames.SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
        log.error("Can't handle request", e);
    }

    return result;
}

From source file:codes.thischwa.c5c.requestcycle.response.mode.FileInfoProperties.java

private String getDate(Date date) {
    if (date == null)
        return null;
    Locale locale = RequestData.getLocale();
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    String dateStr = df.format(date);
    return dateStr;
}

From source file:org.kitodo.data.index.elasticsearch.type.ProcessType.java

@SuppressWarnings("unchecked")
@Override/*from   w w w  .ja  va2 s  . co  m*/
public HttpEntity createDocument(Process process) {

    LinkedHashMap<String, String> orderedProcessMap = new LinkedHashMap<>();
    orderedProcessMap.put("name", process.getTitle());
    orderedProcessMap.put("outputName", process.getOutputName());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String creationDate = process.getCreationDate() != null ? dateFormat.format(process.getCreationDate())
            : null;
    orderedProcessMap.put("creationDate", creationDate);
    orderedProcessMap.put("wikiField", process.getWikiField());
    String project = process.getProject() != null ? process.getProject().getId().toString() : "null";
    orderedProcessMap.put("project", project);
    String ruleset = process.getRuleset() != null ? process.getRuleset().getId().toString() : "null";
    orderedProcessMap.put("ruleset", ruleset);
    String ldapGroup = process.getDocket() != null ? process.getDocket().getId().toString() : "null";
    orderedProcessMap.put("ldapGroup", ldapGroup);

    JSONObject processObject = new JSONObject(orderedProcessMap);

    JSONArray properties = new JSONArray();
    List<ProcessProperty> processProperties = process.getProperties();
    for (ProcessProperty property : processProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    processObject.put("properties", properties);

    return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:br.eti.fernandoribeiro.forge.cloudserverpro.SignatureClientFilter.java

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;//from   w  w w .  ja  va  2 s  .c  o  m

    try {
        ShellMessages.info(shell, "Adding signature to request");

        final Map<String, List<Object>> headers = request.getHeaders();

        final List<Object> value = new ArrayList<Object>();

        final DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");

        final String timestamp = formatter.format(date);

        final Hex encoder = new Hex();

        final MessageDigest digester = MessageDigest.getInstance("SHA1");

        value.add(login + ":" + timestamp + ":" + Base64.encodeBase64String(
                encoder.encode(digester.digest((login + contentLength + timestamp + secretKey).getBytes()))));

        headers.put(HeaderNames.SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
        ShellMessages.error(shell, "Can't handle request");
    }

    return result;
}

From source file:com.qait.automation.utils.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();
    }//from  w  w  w.j  a  v  a  2  s .  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";
        Reporter.log("Save Image File Path : " + saveImgFile, true);
        FileUtils.copyFile(scrFile, new File(saveImgFile));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.moni.automation.utils.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();
    }/*from   ww w  . j av  a2  s . c  om*/

    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";
        Reporter.log("[INFO]: Save Image File Path : " + saveImgFile, true);
        FileUtils.copyFile(scrFile, new File(saveImgFile));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:es.ucm.fdi.dalgs.web.MainController.java

/**
 * Simply selects the home view to render by returning its name.
 *//*from ww w . ja v a 2 s  . co m*/
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@RequestMapping(value = "/home.htm", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! The client locale is {}.", locale);

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);
    model.addAttribute("class", "User");
    model.addAttribute("serverTime", formattedDate);

    return "home";
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * INTERNAL method that returns the build date of the current APK as a string, or null if unable to determine it.
 *
 * @param context    A valid context. Must not be null.
 * @param dateFormat DateFormat to use to convert from Date to String
 * @return The formatted date, or "Unknown" if unable to determine it.
 *//*from  w ww . jav a 2  s. c o m*/
private static String getBuildDateAsString(Context context, DateFormat dateFormat) {
    String buildDate;
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        buildDate = dateFormat.format(new Date(time));
        zf.close();
    } catch (Exception e) {
        buildDate = "Unknown";
    }
    return buildDate;
}

From source file:com.zapprx.testing.end2endtests.automation.utils.TakeScreenshot.java

public void takeScreenshot() {
    screenshotPath = (getProperty("screenshot-path") != null) ? getProperty("screenshot-path") : screenshotPath;
    DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss_ms");
    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();
    }//from   w  w  w. j av a  2 s.  c  om

    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";
        Reporter.log("Save Image File Path : " + saveImgFile, true);
        FileUtils.copyFile(scrFile, new File(saveImgFile));
    } catch (IOException e) {
        e.printStackTrace();
    }
}