List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:DateFormatDemo.java
static public void showDateStyles(Locale currentLocale) { Date today = new Date(); String result;/*from w w w.j av a 2 s. c o m*/ DateFormat formatter; int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; System.out.println(); System.out.println("Locale: " + currentLocale.toString()); System.out.println(); for (int k = 0; k < styles.length; k++) { formatter = DateFormat.getDateInstance(styles[k], currentLocale); result = formatter.format(today); System.out.println(result); } }
From source file:DateFormatDemo.java
static public void showTimeStyles(Locale currentLocale) { Date today = new Date(); String result;/* w ww.j a va 2 s.c o m*/ DateFormat formatter; int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; System.out.println(); System.out.println("Locale: " + currentLocale.toString()); System.out.println(); for (int k = 0; k < styles.length; k++) { formatter = DateFormat.getTimeInstance(styles[k], currentLocale); result = formatter.format(today); System.out.println(result); } }
From source file:com.ln.methods.Descparser.java
public static void parsedesc() { String Desc = ""; String Title = ""; String Hour = ""; String Minute = ""; String formatted[] = new String[Betaparser.Description.length]; int selectedindex = Main.Titlebox.getSelectedIndex(); for (int i1 = 0; i1 != Betaparser.Hours.length; i1++) { if (Betaparser.Events[i1].startsWith(Main.monthday)) { Desc = Desc + "" + Betaparser.Description[i1] + "~"; Title = Title + "" + Betaparser.Title[i1] + "~"; Hour = Hour + "" + Betaparser.Hours[i1] + "~"; Minute = Minute + "" + Betaparser.Minutes[i1] + "~"; }/*from w w w. ja v a 2 s .c o m*/ } String[] Desc2 = StringUtils.substringsBetween(Desc, "", "~"); String[] Title2 = StringUtils.substringsBetween(Title, "", "~"); String[] Hour2 = StringUtils.substringsBetween(Hour, "", "~"); String[] Minute2 = StringUtils.substringsBetween(Minute, "", "~"); String[] Full = new String[Desc2.length]; TTT = ""; DDD = 0; HHH = 0; MMM = 0; for (int i = 0; i != Title2.length; i++) { int h = Integer.parseInt(Hour2[i]); int m = Integer.parseInt(Minute2[i]); DateFormat df = new SimpleDateFormat("dd"); DateFormat dm = new SimpleDateFormat("MM"); Date month = new Date(); Date today = new Date(); int mon = Integer.parseInt(dm.format(month)); int d = Integer.parseInt(df.format(today)); int dif = 0; int ds = 0; int pastd = 0; int pasth = 0; int pastm = 0; d = Main.sdate - d; h = h - Parser.hour; m = m - Parser.minute; if (d > 0) { ds = 1; } if (mon > Main.globmonth) { dif = dif + 1; } if (Main.sdate > d) { dif = dif + 1; } if (h < 0) { pasth = Math.abs(h); } if (m < 0) { pastm = Math.abs(m); h = h - 1; m = m + 60; } if (d < 0) { pastd = d; } if (d > 0 && h < 0) { d = d - 1; h = h + 24; } if (d == 0) { formatted[i] = "<font size=\"4\" color=\"lime\"><br><b>Starts in: " + String.format("%01d Hours %01d Minutes", h, m) + "</b></font>"; } if (d >= 1) { formatted[i] = "<font size=\"4\" color=\"lime\"><br><b>Starts in: " + String.format("%01d Days %01d Hours %01d Minutes", d, h, m) + "</b></font>"; } if (pastd == 0 && h < 0) { formatted[i] = "<font size=\"4\" color=\"#B00000\"><br><b>Event is finished/going on. Started " + String.format("%01d Hours %01d Minutes", pasth, pastm) + " Ago</b></font>"; } if (pastd < 0 && h < 0) { formatted[i] = "<font size=\"4\" color=\"#B00000\"><br><b>Event is finished/going on. Started " + String.format("%01d Days %01d Hours %01d Minutes", pastd, pasth, pastm) + " Ago</b></font>"; } } for (int i = 0; i != Title2.length; i++) { Full[i] = Title2[i]; } try { if (Desc2[selectedindex] != null) { StringBuilder sb = new StringBuilder(Desc2[selectedindex]); int i = 0; while ((i = sb.indexOf(" ", i + 50)) != -1) { // sb.replace(i, i + 1, "<br>"); String formatteddesc = sb.toString(); formatteddesc = formatteddesc.replace("/forum/", "http://www.teamliquid.net/forum/"); TextProcessor processor = BBProcessorFactory.getInstance().create(); formatteddesc = processor.process(formatteddesc); formatteddesc = formatteddesc.replace("#T#", "").replace("#P#", "").replace("#Z#", ""); formatteddesc = formatteddesc.replace("[tlpd#players", "[tlpd][cat]players[/cat]"); formatteddesc = formatteddesc.replace("[/cat]#", "[ID]"); formatteddesc = formatteddesc.replace("sc2-korean]", "[/ID][region]sc2-korean[/region][name]") .replace("sc2-international", "[/ID][region]sc2-international[/region][name]"); formatteddesc = formatteddesc.replace("[/tlpd]", "[/name][/tlpd]"); String[] tlpd = StringUtils.substringsBetween(formatteddesc, "[tlpd]", "[/tlpd]"); String[] cat = StringUtils.substringsBetween(formatteddesc, "[cat]", "[ID]"); String[] ids = StringUtils.substringsBetween(formatteddesc, "[ID]", "[/ID]"); String[] names = StringUtils.substringsBetween(formatteddesc, "[name]", "[/name]"); String[] region = StringUtils.substringsBetween(formatteddesc, "[region]", "[/region]"); try { if (formatteddesc.contains("tlpd")) { formatteddesc = formatteddesc.replace("[tlpd]", "").replace("[/tlpd]", ""); for (int i1 = 0; i1 != tlpd.length; i1++) { formatteddesc = formatteddesc.replace(tlpd[i1], "<a href=\"http://www.teamliquid.net/tlpd/" + cat[i1] + "/" + region[i1] + "/" + ids[i1] + "\">" + names[i1] + "</a>"); // formatteddesc = formatteddesc.replace("[tlpd]", "").replace("[/tlpd]", ""); } } } catch (NullPointerException e) { e.printStackTrace(); } formatteddesc = formatteddesc.replace("<", "").replace("gt;", ""); Main.Description .setText((Full[selectedindex] + formatted[selectedindex] + "<br>" + formatteddesc)); try { if (formatted[selectedindex].contains("lime")) { String[] notfytime = new String[formatted.length]; String[] form = new String[formatted.length]; form[selectedindex] = formatted[selectedindex].replace("Starts in: ", "$"); notfytime[selectedindex] = StringUtils.substringBetween(form[selectedindex], "$", "</b>"); if (formatted[selectedindex].contains("Days")) { String DD = StringUtils.substringBetween(notfytime[selectedindex], "", " Days"); String HH = StringUtils.substringBetween(notfytime[selectedindex], "Days ", " Hours"); String MM = StringUtils.substringBetween(notfytime[selectedindex], "Hours ", " Minutes"); DDD = Integer.parseInt(DD); HHH = Integer.parseInt(HH); MMM = Integer.parseInt(MM); TTT = Full[selectedindex]; } if (!formatted[selectedindex].contains("Days")) { String HH = StringUtils.substringBetween(notfytime[selectedindex], "", " Hours"); String MM = StringUtils.substringBetween(notfytime[selectedindex], "Hours ", " Minutes"); HHH = Integer.parseInt(HH); MMM = Integer.parseInt(MM); TTT = Full[selectedindex]; } } } catch (Exception e) { e.printStackTrace(); } Main.Description.setCaretPosition(0); } } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } }
From source file:edu.monash.merc.util.DMUtil.java
public static String formatDateToUTC(final Date date) { DateFormat simpleDateFormat = new SimpleDateFormat(DATE_UTC_FORMAT, Locale.US); return simpleDateFormat.format(date) + "Z"; }
From source file:de.fuberlin.agcsw.heraclitus.svont.client.core.ChangeLog.java
private static void mapRevisionInformation(OntologyStore os, SVoNtProject sp, ArrayList<ChangeLogElement> changelog) throws MalformedURLException, ParseException, SVNException, SVNClientException { // init for creating SVNUrl SVNUrl rootUrl = new SVNUrl(sp.getRepositoryProjectRootURI().toString()); String rootPath = os.getProject().getLocation().toString() + "/"; String localFile = os.getMainOntologyFile().getLocation().toString(); System.out.println("Ontology local file: " + localFile); SVNUrl svnurl = SVNUrlUtils.getUrlFromLocalFileName(localFile, rootUrl, rootPath); int headRevision = 0; HashMap<Integer, RevisionInfo> revMap = sp.getRevisionInformationMap(); for (ChangeLogElement cle : changelog) { int rev = cle.getRev(); if (rev > headRevision) { headRevision = rev;//ww w . ja v a 2s . co m } SVNRevision r1 = SVNRevision.getRevision(String.valueOf(rev)); ISVNInfo infs = SVNProviderPlugin.getPlugin().getSVNClient().getInfo(svnurl, r1, r1); RevisionInfo revInfo = new RevisionInfo(); revInfo.setRevision(rev); revInfo.setAuthor(infs.getLastCommitAuthor()); Date d = infs.getLastChangedDate(); DateFormat df; df = new SimpleDateFormat("MM/dd/yy HH:mm"); revInfo.setDate(df.format(d)); revMap.put(rev, revInfo); System.out.println(infs.getLastChangedRevision() + " " + infs.getLastChangedDate().toString() + " " + infs.getLastCommitAuthor()); } sp.setRevisionInformationMap(revMap); sp.setHeadRev(headRevision); }
From source file:Dates.java
public static String dateFormatForJSCalendar(Locale locale) { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); String date = df.format(create(1, 2, 1971)); // d, m, y boolean always4InYear = "es".equals(locale.getLanguage()) || "pl".equals(locale.getLanguage()); String result = date.replaceAll("01", "%d").replaceAll("02", "%m").replaceAll("1971", "%Y") .replaceAll("71", always4InYear ? "%Y" : "%y").replaceAll("1", "%d").replaceAll("2", "%m"); return result; }
From source file:net.menthor.editor.v2.util.Util.java
public static String getCompilationDateMessage() { DateFormat dateFormat = new SimpleDateFormat("d, yyyy"); Date date = new Date(); Calendar c = Calendar.getInstance(); return c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + " " + dateFormat.format(date); }
From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java
/** * Show a message stating the JmxDumper has been started, with the current * date and time./* w w w . jav a 2s . c o m*/ */ private static void showStartBanner(PrintWriter out) { DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); out.println(JmxDumpUtil.class.getSimpleName() + " started: " + df.format(new Date())); out.println(); }
From source file:com.easou.common.util.CommonUtils.java
public static String formatForUtcTime(final Date date) { final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return dateFormat.format(date); }
From source file:com.fluidops.iwb.api.ValueResolver.java
/** * Converts a given Calendar object into a human-readable format. * //from w w w . j a v a2 s . c om * @param cal The Calendar object * @param pattern The format pattern used for {@link SimpleDateFormat} * @return A human-readable String */ public static String resolveCalendar(Calendar cal, String pattern) { DateFormat df = new SimpleDateFormat(pattern); return df.format(cal.getTime()); }