List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:org.linkedeconomy.espa.service.impl.rdf.SubProjectsImpl.java
public static void espaSubprojects() throws ParseException { //services for each table ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); SubProjectsService sub = (SubProjectsService) ctx.getBean("subProjectsServiceImpl"); List<SubProjects> subProject = sub.getSubProjects(); //--------------RDF Model--------------// Model model = ModelFactory.createDefaultModel(); Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); InfModel infModel = ModelFactory.createInfModel(reasoner, model); model.setNsPrefix("elod", OntologySpecification.elodPrefix); model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix); model.setNsPrefix("dcterms", OntologySpecification.dctermsPrefix); //number format DecimalFormat df = new DecimalFormat("0.00"); for (SubProjects subProject1 : subProject) { Resource instanceCurrency = infModel.createResource("http://linkedeconomy.org/resource/Currency/EUR"); Resource instanceBudgetUps = infModel.createResource(OntologySpecification.instancePrefix + "UnitPriceSpecification/BudgetItem/" + subProject1.getOps() + "/" + subProject1.getId()); Resource instanceBudget = infModel.createResource(OntologySpecification.instancePrefix + "BudgetItem/" + subProject1.getOps() + "/" + subProject1.getId()); Resource instanceSubProject = infModel.createResource(OntologySpecification.instancePrefix + "Subproject/" + subProject1.getOps() + "/" + subProject1.getId()); Resource instanceProject = infModel .createResource(OntologySpecification.instancePrefix + "Subsidy/" + subProject1.getOps()); DateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy"); DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); java.util.Date stDateStarts; java.util.Date stDateEnds; stDateStarts = dfDate.parse(subProject1.getStart()); stDateEnds = dfDate.parse(subProject1.getFinish()); String startDate = df2.format(stDateStarts); String endDate = df2.format(stDateEnds); infModel.add(instanceProject, RDF.type, OntologySpecification.projectResource); infModel.add(instanceBudgetUps, RDF.type, OntologySpecification.priceSpecificationResource); infModel.add(instanceBudget, RDF.type, OntologySpecification.budgetResource); infModel.add(instanceSubProject, RDF.type, OntologySpecification.subProjectResource); instanceProject.addProperty(OntologySpecification.hasRelatedProject, instanceSubProject); instanceSubProject.addProperty(OntologySpecification.hasRelatedBudgetItem, instanceBudget); instanceBudget.addProperty(OntologySpecification.price, instanceBudgetUps); instanceBudgetUps.addProperty(OntologySpecification.hasCurrencyValue, df.format(subProject1.getBudget()), XSDDatatype.XSDfloat); instanceBudgetUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true", XSDDatatype.XSDboolean); instanceBudgetUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency); instanceSubProject.addProperty(OntologySpecification.startDate, startDate, XSDDatatype.XSDdateTime); instanceSubProject.addProperty(OntologySpecification.endDate, endDate, XSDDatatype.XSDdateTime); instanceSubProject.addProperty(OntologySpecification.title, String.valueOf(subProject1.getTitle()), "el"); }//from w ww. j a v a2s. c o m try { FileOutputStream fout = new FileOutputStream( "/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/subProjectEspa.rdf"); model.write(fout); } catch (IOException e) { System.out.println("Exception caught" + e.getMessage()); } }
From source file:at.asitplus.regkassen.core.base.util.CashBoxUtils.java
/** * Method that converts a Java date to an ISO 8601 string * * @param date Java date to be converted to an ISO 8601 string * @return the date converted to an ISO 8601 string *///from ww w . ja va 2s . c o m public static String convertDateToISO8601(Date date) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); return dateFormat.format(date); }
From source file:ru.org.linux.topic.TopicListDaoImpl.java
/** * ? SQL-?.// w ww . j av a 2 s .c o m * * @param topicListDto , ? ?? * @return ?, ?? ?? SQL-? */ private static String makeConditions(TopicListDto topicListDto) { StringBuilder where = new StringBuilder("NOT deleted"); where.append(topicListDto.getCommitMode().getQueryPiece()); if (!topicListDto.getSections().isEmpty()) { StringBuilder whereSections = new StringBuilder(); for (Integer section : topicListDto.getSections()) { if (section == null || section == 0) { continue; } if (whereSections.length() != 0) { whereSections.append(','); } whereSections.append(section); } if (whereSections.length() != 0) { where.append(" AND section in (").append(whereSections).append(')'); } } if (topicListDto.getGroup() != 0) { where.append(" AND groupid=").append(topicListDto.getGroup()); } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); switch (topicListDto.getDateLimitType()) { case BETWEEN: where.append(" AND postdate>='").append(dateFormat.format(topicListDto.getFromDate())) .append("'::timestamp AND postdate<'").append(dateFormat.format(topicListDto.getToDate())) .append("'::timestamp "); break; case MONTH_AGO: where.append("AND postdate>'").append(dateFormat.format(topicListDto.getFromDate())) .append("'::timestamp "); break; default: } if (topicListDto.getUserId() != 0) { if (topicListDto.isUserFavs()) { where.append(" AND memories.userid=").append(topicListDto.getUserId()); } else { where.append(" AND userid=").append(topicListDto.getUserId()); } if (topicListDto.isUserFavs()) { if (topicListDto.isUserWatches()) { where.append(" AND watch "); } else { where.append(" AND NOT watch "); } } } if (topicListDto.isNotalks()) { where.append(" AND not topics.groupid=8404"); } if (topicListDto.isTech()) { where.append(" AND not topics.groupid=8404 AND not topics.groupid=4068 AND groups.section=2"); } if (topicListDto.getTag() != 0) { where.append(" AND topics.id IN (SELECT msgid FROM tags WHERE tagid=").append(topicListDto.getTag()) .append(')'); } return where.toString(); }
From source file:com.opensymphony.util.FileUtils.java
public final static void writeAndBackup(File file, String content) { try {/*from w w w . j a v a2 s.c o m*/ DateFormat backupDF = new SimpleDateFormat("ddMMyy_hhmmss"); File backupDirectory = checkBackupDirectory(file); File original = new File(file.getAbsolutePath()); File backup = new File(backupDirectory, original.getName() + "." + backupDF.format(new Date())); if (log.isDebugEnabled()) { log.debug("Backup file is " + backup); } original.renameTo(backup); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(content); out.close(); } catch (FileNotFoundException e) { log.warn("File not found", e); } catch (IOException e) { log.error(e); } }
From source file:com.piketec.jenkins.plugins.tpt.Utils.java
/** * @param format/*w w w . ja va 2 s .c o m*/ * @param date * @return formatted date */ static String formatDate(DateFormat format, Date date) { synchronized (format) { return format.format(date); } }
From source file:edu.monash.merc.util.DMUtil.java
public static String genCurrentTimestamp() { Date date = GregorianCalendar.getInstance().getTime(); DateFormat df = new SimpleDateFormat(DATE_FORMAT2); return df.format(date); }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Formats a date for display in the application. * * @param applicationContext The application context. * @param date The date to format. * @param hideTime Omits the time in the formatted date if true. * @return the formatted date.//from w w w. j ava 2s. c o m */ public static String getFormattedDate(Context applicationContext, Date date, boolean hideTime) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar oneMinuteAgo = Calendar.getInstance(); oneMinuteAgo.add(Calendar.MINUTE, -1); if (oneMinuteAgo.getTime().before(date)) { // Last minute: X seconds ago long seconds = (Calendar.getInstance().getTime().getTime() - calendar.getTime().getTime()) / 1000; if (seconds < 10) { return applicationContext.getString(R.string.utils_date_just_now); } else { return seconds + " " + applicationContext.getString(R.string.utils_date_seconds_ago); } } Calendar oneHourAgo = Calendar.getInstance(); oneHourAgo.add(Calendar.HOUR_OF_DAY, -1); if (oneHourAgo.getTime().before(date)) { // Last hour: X minutes ago long minutes = (Calendar.getInstance().getTime().getTime() - calendar.getTime().getTime()) / (1000 * 60); if (minutes == 1) { return applicationContext.getString(R.string.utils_date_one_minute_ago); } else { return minutes + " " + applicationContext.getString(R.string.utils_date_minutes_ago); } } if (compareDateWithoutTime(Calendar.getInstance(), calendar) == 0) { // Today: h:mm a DateFormat format = new SimpleDateFormat("h:mm a", Locale.getDefault()); return format.format(date); } if (Calendar.getInstance().get(Calendar.WEEK_OF_YEAR) == calendar.get(Calendar.WEEK_OF_YEAR) && Calendar.getInstance().get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) { if (hideTime) { // This week: EEE DateFormat format = new SimpleDateFormat("EEE", Locale.getDefault()); return format.format(date); } else { // This week: EEE h:mm a DateFormat format = new SimpleDateFormat("EEE h:mm a", Locale.getDefault()); return format.format(date); } } if (Calendar.getInstance().get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) { if (hideTime) { // This year: MMM d DateFormat format = new SimpleDateFormat("MMM d", Locale.getDefault()); return format.format(date); } else { // This year: MMM d h:mm a DateFormat format = new SimpleDateFormat("MMM d, h:mm a", Locale.getDefault()); return format.format(date); } } if (hideTime) { // Any: MMM d, yyyy DateFormat format = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault()); return format.format(date); } else { // Any: MMM d, yyyy h:mm a DateFormat format = new SimpleDateFormat("MMM d, yyyy, h:mm a", Locale.getDefault()); return format.format(date); } }
From source file:com.krawler.common.util.SchedulingUtilities.java
public static int CountCmpHolidays(Date stdate, Date enddate, String[] CmpHoliDays) { int NonWorkingDays = 0; Calendar c1 = Calendar.getInstance(); DateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); try {/*from w w w . j av a2 s .c o m*/ c1.setTime(stdate); while ((stdate.compareTo(enddate)) < 0) { if (Arrays.binarySearch(CmpHoliDays, sdf1.format(c1.getTime())) >= 0) { NonWorkingDays += 1; } c1.add(Calendar.DATE, 1); stdate = c1.getTime(); } } catch (Exception e) { System.out.print(e.getMessage()); } return NonWorkingDays; }
From source file:eu.wordnice.wnconsole.WNCUtils.java
public static String replaceBuiltinVars(String in) { String nev = Api.getColoredString(in).replace("$n", "\n").replace("$t", " ").replace("\t", " ") .replace("$server_ip", Bukkit.getIp()).replace("$port", "" + Bukkit.getPort()) .replace("$motd", Bukkit.getMotd()).replace("$max_players", "" + Bukkit.getMaxPlayers()) .replace("$time", "" + System.currentTimeMillis()) /*//from w w w . j a v a2 s . c o m * When compiling for newer versions, change to * .replace("$players", "" + Bukkit.getOnlinePlayers().size()); */ .replace("$players", "" + Bukkit.getOnlinePlayers().length); int befend = 0; while (true) { int start = nev.indexOf("$date[[", befend); if (start != -1) { int end = nev.lastIndexOf("]]", start + 7); if (end != -1) { if (end == start + 7) { String formatdate = new Date().toString(); befend = start + formatdate.length(); nev = nev.substring(0, start) + formatdate + nev.substring(end + 2, nev.length()); } try { DateFormat tf = new SimpleDateFormat(nev.substring(start + 7, end)); String formatdate = tf.format(new Date()); befend = start + formatdate.length(); nev = nev.substring(0, start) + formatdate + nev.substring(end + 2, nev.length()); } catch (Throwable t) { String formatdate = new Date().toString(); befend = start + formatdate.length(); nev = nev.substring(0, start) + formatdate + nev.substring(end + 2, nev.length()); } } else { break; } } else { break; } } return nev.replace("$date", new Date().toString()); }
From source file:com.mercandalli.android.apps.files.main.Config.java
public static String getUserToken() { final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US); df.setTimeZone(TimeZone.getTimeZone("gmt")); final String currentDate = df.format(new Date()); String log = ENUM_String.STRING_USER_USERNAME.value; String pass = HashUtils.sha1(HashUtils.sha1(ENUM_String.STRING_USER_PASSWORD.value) + currentDate); String authentication = String.format("%s:%s", log, pass); return Base64.encodeBytes(authentication.getBytes()); }