List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:de.terrestris.shogun.serializer.DateSerializer.java
/** * Overwrite the original serialize and return a String representation of * the java.util.Date-instance./*from w w w . j a v a 2 s . c o m*/ */ @Override public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); jgen.writeString(formatter.format(new Date(value.getTime()))); }
From source file:org.kitodo.data.elasticsearch.index.type.BaseType.java
/** * Method used for formatting Date as String. It will help to change fast a * way of Date formatting or expected String format. * * @param date/*from w w w .jav a 2s . co m*/ * as Date * @return formatted date as String */ String formatDate(Date date) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateFormat.format(date); }
From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java
/** * Builds the HTML code for a select box of months.<p> * // ww w . j ava2s.c o m * @param timeMillis the time in milliseconds which should be preselected * @param fieldName the prefix of the name attribute * @param attributes optional additional attributes of the select tag * @param localeString the current locale String * @return the HTML code for a select box of months */ public static String buildSelectMonth(long timeMillis, String fieldName, String attributes, String localeString) { StringBuffer retValue = new StringBuffer(512); Locale locale = new Locale(localeString); Calendar cal = new GregorianCalendar(locale); cal.setTimeInMillis(timeMillis); Calendar calTemp = new GregorianCalendar(locale); calTemp.setTimeInMillis(timeMillis); // set day to 2 to avoid display errors for days 29, 30 and 31 calTemp.set(Calendar.DAY_OF_MONTH, 2); DateFormat df = new SimpleDateFormat("MMMM", locale); retValue.append("<select name=\"" + fieldName + "month\""); if (attributes != null) { retValue.append(" " + attributes); } retValue.append(">\n"); for (int i = 0; i < 12; i++) { calTemp.set(Calendar.MONTH, i); retValue.append("\t<option value=\"" + (i + 1) + "\""); if (cal.get(Calendar.MONTH) == i) { retValue.append(" selected=\"selected\""); } retValue.append(">" + df.format(calTemp.getTime()) + "</option>\n"); } retValue.append("</select>\n"); return retValue.toString(); }
From source file:csns.web.controller.RubricAssignmentController.java
@RequestMapping("/rubric/assignment/publish") @ResponseBody/* w ww. ja va 2 s. c o m*/ public String publish(@RequestParam Long id) throws IOException { RubricAssignment assignment = rubricAssignmentDao.getRubricAssignment(id); if (!assignment.isPublished()) { assignment.setPublishDate(Calendar.getInstance()); assignment = rubricAssignmentDao.saveRubricAssignment(assignment); logger.info( SecurityUtils.getUser().getUsername() + " published rubric assignment " + assignment.getId()); } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); return dateFormat.format(assignment.getPublishDate().getTime()); }
From source file:org.kitodo.data.index.elasticsearch.type.HistoryType.java
@SuppressWarnings("unchecked") @Override/* www . jav a2 s . c o m*/ public HttpEntity createDocument(History history) { LinkedHashMap<String, String> orderedHistoryMap = new LinkedHashMap<>(); orderedHistoryMap.put("numericValue", history.getNumericValue().toString()); orderedHistoryMap.put("stringValue", history.getStringValue()); orderedHistoryMap.put("type", history.getHistoryType().toString()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String date = history.getDate() != null ? dateFormat.format(history.getDate()) : null; orderedHistoryMap.put("date", date); orderedHistoryMap.put("process", history.getProcess().getId().toString()); JSONObject historyObject = new JSONObject(orderedHistoryMap); return new NStringEntity(historyObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:securitytools.veracode.http.request.CreateBuildRequest.java
public CreateBuildRequest(String applicationId, String versionName) { super("/api/4.0/createbuild.do"); if (applicationId == null) { throw new IllegalArgumentException("Application id cannot be null."); }/*from w w w . ja v a 2s . c o m*/ List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("app_id", applicationId)); if (versionName == null) { DateFormat formatter = new SimpleDateFormat(VERSION_DATE_FORMAT); versionName = formatter.format(new Date()); } formparams.add(new BasicNameValuePair("version", versionName)); setEntity(new UrlEncodedFormEntity(formparams, Consts.UTF_8)); }
From source file:be.wegenenverkeer.common.resteasy.web.SampleServiceImpl.java
private String sample(String query, String gatewayMethod) { waitALittle();//from ww w. ja v a2 s . co m if (null == query || (query.length() % 2) == 0) { // do a dummy gateway call callGateway(gatewayMethod); } DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS"); return "done at " + dateFormat.format(new Date()); }
From source file:demo.task.TimestampTask.java
@Bean protected Tasklet tasklet() { return new Tasklet() { @Override/*from ww w .j a v a 2s . c o m*/ public RepeatStatus execute(StepContribution contribution, ChunkContext context) { DateFormat dateFormat = new SimpleDateFormat(config.getFormat()); logger.info(dateFormat.format(new Date())); return RepeatStatus.FINISHED; } }; }
From source file:com.job.portal.HomeController.java
@RequestMapping(value = "/test", method = RequestMethod.GET) public String home(Locale locale, Model model) { System.out.println("Welcome Client krish change " + locale.getCountry()); 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:com.truthbean.demo.ssm.controller.HomeController.java
/** * Simply selects the home view to render by returning its name. *///from w w w . ja va 2 s . c o m @RequestMapping(value = "/index.html", 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); System.out.println(formattedDate); model.addAttribute("serverTime", formattedDate); return "view/home"; }