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:be.bittich.dynaorm.maping.BasicColumnMapping.java

private String doFilterBeforeApplyToString(Object object) {
    String valString = object.toString();
    //check if it's a date
    if (object instanceof Date) {
        DateFormat sdf = new SimpleDateFormat(Dialect.DATE_FORMAT);
        valString = sdf.format((Date) object);
    }//  www .j  a  va2s .c o  m
    return valString;
}

From source file:com.tcloud.bee.key.server.mvc.controller.HomeController.java

/**
 * Simple controller for "/" that returns a Thymeleaf view.
 *///  ww w.j a v  a 2 s.c o  m
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! the client locale is " + locale.toString());

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    logger.trace("Authentication principal: {}", auth.getPrincipal());
    logger.trace("Authentication name: {}", auth.getName());

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

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);
    // model.addAttribute("echoService", echoService);
    model.addAttribute("someItems", new String[] { "one", "two", "three" });

    return "home";
}

From source file:net.sf.sze.jobs.DatabaseBackupJob.java

/**
 * Sicherung einer H2-Datenbank./*from   w w  w.  j  a va2s . c  o m*/
 */
@Scheduled(cron = "${cron.dbBackup}") //
public void backupH2Database() {
    if (env.getProperty("spring.datasource.driver-class-name").equals("org.h2.Driver")) {
        final String backupDir = env.getProperty("backupDir", "databases/backup");
        final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
        final File backupFile = new File(backupDir, "sze_" + dateFormat.format(new Date()) + ".zip");
        final String backupCmd = "BACKUP TO '" + backupFile.getAbsolutePath() + "'";
        LOG.info("Backup to {}", backupFile.getAbsolutePath());
        try (Connection conn = dataSource.getConnection()) {
            conn.createStatement().execute(backupCmd);
        } catch (SQLException sqlE) {
            LOG.error("Couldn't create Database-Backup!", sqlE);
        }
    }

}

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

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;//from w  ww  . jav  a  2s.  c  om

    try {
        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.API_SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
    }

    return result;
}

From source file:org.croodie.resource.RootServerResource.java

@Get("json")
public String represent() {
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
            Locale.getDefault());
    String formattedDate = dateFormat.format(date);
    return formattedDate;
}

From source file:org.mm.demo.portlet.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *///from w w w.  ja v a  2  s  . com
@RenderMapping
public String home(final Locale locale, final Model model) {
    LOG.info("Welcome home! the client locale is {}", locale.toString());

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

    final String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);
    model.addAttribute("organizationLocalServiceBeanIdentifier", organizationLocalService.getBeanIdentifier());

    return "home";
}

From source file:org.uom.fit.level2.datavis.controllers.chatController.ChatController.java

@RequestMapping(value = { "/save" }, method = RequestMethod.POST)
@ResponseBody//www .j  ava 2 s .com
public String LoginPage(@RequestBody ChatData chatData) {
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    Date today = Calendar.getInstance().getTime();
    String reportDate = df.format(today);
    chatData.setDateTime(reportDate);
    boolean val = chatServices.saveChatData(chatData);
    if (val == true) {
        return "suss";
    } else {
        return "fail";
    }
}

From source file:ipat_fx.IPAT_FX.java

@Override
public void start(Stage stage) throws Exception {
    String contextPath = System.getProperty("user.dir") + "/web/";
    File logFile = new File(contextPath + "/log/log4j-IPAT.log");
    System.setProperty("rootPath", logFile.getAbsolutePath());

    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);/* w w  w .ja v a2  s.  c  om*/
    stage.show();
    stage.setOnHiding((WindowEvent event) -> {
        Platform.runLater(() -> {
            File src = new File(contextPath + "/Client Data");
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
            Date date = new Date();
            File dest = new File(contextPath + "/Saves/Ipat_" + dateFormat.format(date));
            if (!dest.exists()) {
                dest.mkdirs();
            }
            try {
                FileUtils.copyDirectory(src, dest);
            } catch (IOException ex) {
                Logger.getLogger(IPAT_FX.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.exit(0);
        });
    });
}

From source file:org.jasig.portlet.test.mvc.tests.ExceptionThrowingTest.java

protected String getFormattedDate() {
    final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
    return dateFormat.format(new Date());
}

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

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

    try {
        LOGGER.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) {
        LOGGER.log(Level.SEVERE, "Can't handle request", e);
    }

    return result;
}