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:csns.web.controller.RubricController.java

@RequestMapping("/department/{dept}/rubric/publish")
public @ResponseBody String publish(@RequestParam Long id) {
    Rubric rubric = rubricDao.getRubric(id);
    if (!rubric.isPublished()) {
        rubric.setPublishDate(Calendar.getInstance());
        rubric = rubricDao.saveRubric(rubric);
        logger.info(SecurityUtils.getUser().getUsername() + " published rubric " + rubric.getId());
    }//from w  w  w  . ja va  2s .  c  o  m

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    return dateFormat.format(rubric.getPublishDate().getTime());
}

From source file:ph.fingra.statisticsweb.controller.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *//*w  w  w.  ja v a  2s . c o  m*/
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(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("serverTime", formattedDate);

    // database & mybatis db mapper test
    model.addAttribute("memberlist", memberService.getList());

    // admin.properties test
    Member admin = new Member();
    admin.setEmail(adminEmail);
    admin.setName(adminName);
    admin.setPassword(adminPassword);
    admin.setRole(MemberRole.ROLE_ADMIN.getValue());
    model.addAttribute("admin", admin);

    return "test";
}

From source file:fr.olympicinsa.riocognized.model.ImageCommon.java

public String getCreated() {
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    return dateFormat.format(created);
}

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

/**
 * Returns a formatted date string from a raw date.
 * @param s the raw date string (e.g. "2015-05-14T23:38:47Z")
 * @return the formatted date, or the raw string if it could not be parsed
 *//*from  w w w  . ja  v a  2 s  . co m*/
private String formatDate(String s) {
    try {
        DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        f.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date d = f.parse(s);
        DateFormat fmt = new SimpleDateFormat("d MMM yyyy HH:mm:ss");
        return fmt.format(d);
    } catch (ParseException e) {
        return s;
    }
}

From source file:Activities.java

private String addData(String endpoint) {
    String data = null;/*from   w w  w .j  a v  a2  s. c  om*/
    try {
        // Construct request payload
        JSONObject attrObj = new JSONObject();
        attrObj.put("name", "URL");
        attrObj.put("value", "http://www.nvidia.com/game-giveaway");

        JSONArray attrArray = new JSONArray();
        attrArray.add(attrObj);

        TimeZone tz = TimeZone.getTimeZone("UTC");
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
        df.setTimeZone(tz);
        String dateAsISO = df.format(new Date());

        // Required attributes
        JSONObject obj = new JSONObject();
        obj.put("leadId", "1001");
        obj.put("activityDate", dateAsISO);
        obj.put("activityTypeId", "1001");
        obj.put("primaryAttributeValue", "Game Giveaway");
        obj.put("attributes", attrArray);
        System.out.println(obj);

        // Make request
        URL url = new URL(endpoint);
        HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
        urlConn.setRequestMethod("POST");
        urlConn.setAllowUserInteraction(false);
        urlConn.setDoOutput(true);
        urlConn.setRequestProperty("Content-type", "application/json");
        urlConn.setRequestProperty("accept", "application/json");
        urlConn.connect();
        OutputStream os = urlConn.getOutputStream();
        os.write(obj.toJSONString().getBytes());
        os.close();

        // Inspect response
        int responseCode = urlConn.getResponseCode();
        if (responseCode == 200) {
            System.out.println("Status: 200");
            InputStream inStream = urlConn.getInputStream();
            data = convertStreamToString(inStream);
            System.out.println(data);
        } else {
            System.out.println(responseCode);
            data = "Status:" + responseCode;
        }
    } catch (MalformedURLException e) {
        System.out.println("URL not valid.");
    } catch (IOException e) {
        System.out.println("IOException: " + e.getMessage());
        e.printStackTrace();
    }

    return data;
}

From source file:com.produban.openbus.processor.function.ParseJSON.java

@Override
public final void execute(final TridentTuple tuple, final TridentCollector collector) {
    try {/*from ww w  . j  a  v a2  s .  co  m*/
        String decoded = new String(tuple.getBinary(0));
        JSONObject json = new JSONObject(decoded);

        // Date message
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        String dateNow = dateFormat.format(cal.getTime());
        json.accumulate("date", dateNow);
        LOG.info("##### name: " + json.get("name") + " type: " + json.get("type") + " date: "
                + json.getString("date"));

        // Persitence in HDFS             
        hDFSStore.writeFile2HDFS("json" + "_" + System.nanoTime(), json.toString());

        collector.emit(new Values(json.getString("name"), json.getString("type")));
    } catch (Exception e) {
        LOG.error("Caught JSONException: " + e.getMessage());
        throw new RuntimeException(e);
    }
}

From source file:com.diversityarrays.kdxplore.curate.TypedSampleMeasurement.java

/**
 * Return null if all the DeviceNames are unique else
 * the shortFormat if it is sufficient to uniquely identify the TypedSampleMeasurements
 * @param coll/*from w  ww  .  jav a  2s .  co  m*/
 * @param shortFormat
 * @param longFormat
 * @return
 */
static public DateFormat getDateFormatForUniqueIdent(Collection<TypedSampleMeasurement> coll,
        DateFormat shortFormat, DateFormat longFormat) {
    Map<String, Bag<String>> datesByDeviceName = new HashMap<>();

    boolean foundDuplicateDeviceName = false;
    for (TypedSampleMeasurement tsm : coll) {
        if (DeviceType.KDSMART == tsm.deviceIdentifier.getDeviceType()) {
            String deviceName = tsm.deviceIdentifier.getDeviceName();
            if (datesByDeviceName.containsKey(deviceName)) {
                foundDuplicateDeviceName = true;
            } else {
                datesByDeviceName.put(deviceName, new HashBag<>());
            }
        }
    }
    if (!foundDuplicateDeviceName) {
        return null;
    }

    for (TypedSampleMeasurement tsm : coll) {
        if (DeviceType.KDSMART == tsm.deviceIdentifier.getDeviceType()) {
            String deviceName = tsm.deviceIdentifier.getDeviceName();

            Bag<String> bag = datesByDeviceName.get(deviceName);
            if (tsm.sampleGroupDate != null) {
                String s = longFormat.format(tsm.sampleGroupDate);
                bag.add(s);
            }
        }
    }

    for (Bag<String> bag : datesByDeviceName.values()) {
        for (String key : bag.uniqueSet()) {
            if (bag.getCount(key) > 1) {
                return longFormat;
            }
        }
    }

    return shortFormat;
}

From source file:fr.paris.lutece.plugins.workflow.modules.rest.service.formatters.WorkflowFormatterJson.java

/**
 * {@inheritDoc }//from   w w w  .  j av a 2s  .  c  o  m
 */
@Override
public String format(Workflow workflow) {
    JSONObject jsonObject = new JSONObject();

    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, I18nService.getDefaultLocale());
    String strDate = dateFormat.format(workflow.getCreationDate());

    jsonObject.element(WorkflowRestConstants.TAG_ID_WORKFLOW, workflow.getId());
    jsonObject.element(WorkflowRestConstants.TAG_NAME, workflow.getName());
    jsonObject.element(WorkflowRestConstants.TAG_DESCRIPTION, workflow.getDescription());
    jsonObject.element(WorkflowRestConstants.TAG_CREATION_DATE, strDate);
    jsonObject.element(WorkflowRestConstants.TAG_IS_ENABLE, Boolean.toString(workflow.isEnabled()));
    jsonObject.element(WorkflowRestConstants.TAG_WORKGROUP_KEY, workflow.getWorkgroup());

    return jsonObject.toString();
}

From source file:com.olegchir.fadeok.controller.AppController.java

@RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
public String home(Locale locale, Model model) {

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    String formattedDate = dateFormat.format(date);
    model.addAttribute("serverTime", formattedDate);

    return "home";
}

From source file:no.dusken.aranea.admin.editor.CalendarEditor.java

@Override
public String getAsText() {
    DateFormat formatter = new SimpleDateFormat(format, new Locale("no"));
    Calendar cal = (GregorianCalendar) getValue();
    if (cal != null) {
        return formatter.format(cal.getTime());
    } else {//from ww  w  . java  2 s  .  co  m
        return null;
    }
}