Java Text Format Class Example
Java Code Examples for java.text.Format
The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.
Example 1
From project CIShell, under directory /core/org.cishell.utilities/src/org/cishell/utilities/.
Source file: NumberUtilities.java
26
public static String convertToDecimalNotation(String numberAsString){ if (numberAsString.indexOf("E") != -1 || numberAsString.indexOf("e") != -1) { Format format=new DecimalFormat(UNROUNDED_DECIMAL_PATTERN); try { return format.format(new Double(numberAsString)); } catch ( NumberFormatException numberFormatException) { return NOT_A_NUMBER_PREFIX + " (" + numberAsString+ ")"; } } return numberAsString; }
Example 2
public DateEncodedPathProcessor(){ Calendar cal=Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); if (timeUnit.equals("hour")) { cal.add(Calendar.HOUR_OF_DAY,-timeInterval); } else { cal.add(Calendar.DAY_OF_MONTH,-timeInterval); } Format formatter=new SimpleDateFormat("yyyy-MM-dd-HH"); date=formatter.format(cal.getTime()); }
Example 3
From project Zypr-Reference-Client---Java, under directory /source/net/zypr/gui/windows/.
Source file: AgendaItemListWindow.java
26
private void updateDateFields(){ Date date=_currentDate.getTime(); Format formatter=new SimpleDateFormat("MMM"); _labelMonth.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("d"); _labelDay.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("yyyy"); _labelYear.setText(formatter.format(date).toString()); formatter=new SimpleDateFormat("MMMM d, yyyy"); setTitle("Agenda for " + formatter.format(date).toString()); formatter=null; }
Example 4
From project Zypr-Reference-Client---Java, under directory /source/net/zypr/gui/windows/.
Source file: SettingsUnitsWindow.java
26
private void updateTimeDate(){ Date date=Calendar.getInstance().getTime(); TimeFormatPattern timeFormatPattern=TimeFormatPattern.values()[_selectedTimeFormatIndex]; Format formatter=new SimpleDateFormat(timeFormatPattern.getPattern()); _labelTimeFormatValue.setText("<html><center>" + formatter.format(date).toString() + "<br/>("+ timeFormatPattern.getPattern()+ ")</center></html>"); formatter=null; DateFormatPattern dateFormatPattern=DateFormatPattern.values()[_selectedDateFormatIndex]; formatter=new SimpleDateFormat(dateFormatPattern.getPattern()); _labelDateFormatValue.setText("<html><center>" + formatter.format(date).toString() + "<br/>("+ dateFormatPattern.getPattern()+ ")</center></html>"); formatter=null; }
Example 5
From project GenericKnimeNodes, under directory /com.genericworkflownodes.knime.base_plugin/src/com/genericworkflownodes/knime/nodes/io/viewer/.
Source file: MimeFileViewerNodeModel.java
25
public static String readFileSummary(File file,int maxLines) throws IOException { BufferedReader br=new BufferedReader(new FileReader(file)); StringBuffer sb=new StringBuffer(); String line=""; int cnt=0; sb.append("File path: " + file.getAbsolutePath() + System.getProperty("line.separator")); sb.append("File size: " + file.length() + " bytes"+ System.getProperty("line.separator")); Date date=new Date(file.lastModified()); Format formatter=new SimpleDateFormat("yyyy.MM.dd HH.mm.ss"); String s=formatter.format(date); sb.append("File time: " + s + System.getProperty("line.separator")); sb.append(String.format("File content (first %d lines):" + System.getProperty("line.separator"),maxLines)); while ((line=br.readLine()) != null) { sb.append(line + System.getProperty("line.separator")); cnt++; if (cnt > maxLines) { sb.append("######### OUTPUT TRUNCATED #########" + System.getProperty("line.separator")); break; } } return sb.toString(); }
Example 6
From project groundhog-reader, under directory /src/main/java/com/almarsoft/GroundhogReader/lib/.
Source file: MessagePosterLib.java
25
private String createHeaderData() throws EncoderException { String references, from, name, email, date; Date now=new Date(); Format formatter=new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z",Locale.US); date=formatter.format(now); Charset headerCharset=CharsetUtil.getCharset(mPostCharset); String tmpName=mPrefs.getString("name","anonymous"); if (EncoderUtil.hasToBeEncoded(tmpName,0)) { name=EncoderUtil.encodeEncodedWord(tmpName,EncoderUtil.Usage.TEXT_TOKEN,0,headerCharset,null); } else name=tmpName; email="<" + mPrefs.getString("email","[email protected]").trim() + ">"; from=name + " " + email; if (EncoderUtil.hasToBeEncoded(mSubject,0)) { mSubject=EncoderUtil.encodeEncodedWord(mSubject,EncoderUtil.Usage.TEXT_TOKEN,0,headerCharset,null); } SimpleNNTPHeader header=new SimpleNNTPHeader(from,mSubject); String[] groups=mGroups.trim().split(","); for ( String group : groups) { header.addNewsgroup(group); } header.addHeaderField("Date",date); header.addHeaderField("Content-Type","text/plain; charset=" + CharsetUtil.toMimeCharset(mPostCharset) + "; format=flowed"); header.addHeaderField("Content-Transfer-Encoding","8bit"); if (mReferences != null) { if (mPrevMsgId != null) { references=mReferences + " " + mPrevMsgId; header.addHeaderField("In-Reply-To",mPrevMsgId); } else { references=mReferences; } header.addHeaderField("References",references); } mMyMsgId=generateMsgId(); header.addHeaderField("Message-ID",mMyMsgId); header.addHeaderField("User-Agent","Groundhog Newsreader for Android"); return header.toString(); }
Example 7
From project Newsreader, under directory /bundles/org.eclipse.ecf.salvo.ui/src/org/eclipse/ecf/salvo/ui/tools/.
Source file: DateUtils.java
25
/** * Makes a pleasant readable date like "today 12:15" or "12:15" * @param article * @param date RFC822 Date * @return a pleasant readable date */ public String getNiceDate(IArticle article,Date date){ if (date != null) { Date now=new Date(); Format formatter=new SimpleDateFormat("dd/MM/yy"); String today=formatter.format(now); String articleDate=formatter.format(date); String formattedDate=DateFormat.getInstance().format(date); if (today.equals(articleDate)) { String[] fD=formattedDate.split(" "); if (fD.length == 2) { return "Today " + fD[1]; } else if (fD.length == 3) { return "Today " + fD[1] + " "+ fD[2]; } } return formattedDate; } return article.getDate(); }
Example 8
From project org.openscada.external, under directory /org.openscada.external.jOpenDocument/src/org/jopendocument/util/.
Source file: FormatGroup.java
25
@Override public Object parseObject(String s,ParsePosition pos){ if (pos.getErrorIndex() >= 0) throw new IllegalArgumentException(pos + " has en error at " + pos.getErrorIndex()); boolean success=false; Object tmpRes=null; final ParsePosition tmpPos=new ParsePosition(pos.getIndex()); final Iterator<? extends Format> iter=this.formats.iterator(); while (iter.hasNext() && !success) { final Format f=iter.next(); mutateTo(tmpPos,pos); tmpRes=f.parseObject(s,tmpPos); success=tmpPos.getIndex() != pos.getIndex() && tmpPos.getErrorIndex() < 0; } final Object res; if (!success) { res=this.formats.get(this.formatIndex).parseObject(s,pos); } else { res=tmpRes; mutateTo(pos,tmpPos); } return res; }
Example 9
From project scooter, under directory /source/src/com/scooterframework/web/util/.
Source file: T.java
25
/** * Returns a text of number. * @param number the object * @param pattern the pattern format of the result * @param locale the locale of the result * @return a number text */ public static String textOfNumber(Object number,String pattern,Locale locale){ if (number == null) return ""; if (pattern == null || "".equals(pattern)) return number.toString(); if (locale == null) locale=ACH.getAC().getLocale(); String formattedValue=""; try { Format nf=NumberFormat.getNumberInstance(locale); if (pattern != null && !"".equals(pattern)) { ((DecimalFormat)nf).applyPattern(pattern); } if (number instanceof Number) { formattedValue=nf.format(number); } else { if (number instanceof String) { formattedValue=nf.format(new Double((String)number)); } } } catch ( NumberFormatException ex) { ; } return formattedValue; }
Example 10
@Override public Object convert(Object pvObject,Class<?> pvToType){ Object lvReturn=pvObject; Class<?> lvClass=lvReturn.getClass(); Format lvFormat=null; if (lvClass.equals(String.class) && pvToType != null) { try { lvFormat=formatter.get(pvToType); if (lvFormat != null) { lvReturn=lvFormat.parseObject(lvReturn.toString()); } } catch ( ParseException e) { throw new ConversionException("Can't convert value: " + lvReturn + " to: "+ pvToType.getName()); } } else { lvFormat=formatter.get(lvClass); if (lvFormat != null) { lvReturn=lvFormat.format(lvReturn); } } return lvReturn; }
Example 11
From project Zypr-Reference-Client---Java, under directory /source/net/zypr/gui/windows/.
Source file: AgendaEditWindow.java
25
private void updateDateFields(){ Date date=_currentDate.getTime(); Format formatter=new SimpleDateFormat("MMM"); _labelMonth.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("d"); _labelDay.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("yyyy"); _labelYear.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("KK"); _labelHour.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("m"); _labelMinute.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("a"); _labelAMPM.setText(formatter.format(date).toString()); formatter=null; formatter=new SimpleDateFormat("MMMM d, yyyy KK:mm a"); setTitle("Agenda item for " + formatter.format(date).toString()); formatter=null; }
Example 12
From project core_4, under directory /impl/src/main/java/org/richfaces/util/.
Source file: Util.java
23
public static Date parseHttpDate(String s){ Date result=null; if (s != null) { try { result=(Date)((Format)RFC1123_DATE_FORMATTER.clone()).parseObject(s); } catch ( ParseException e) { RESOURCE_LOGGER.error(e.getMessage(),e); } } return result; }
Example 13
From project core_4, under directory /impl/src/main/java/org/richfaces/util/.
Source file: Util.java
23
public static String formatHttpDate(Object object){ if (object != null) { return ((Format)RFC1123_DATE_FORMATTER.clone()).format(object); } else { return null; } }
Example 14
private void print(Chunk changed,String type){ m_result.append(CSS_DIFF_UNCHANGED); String[] choiceString={m_rb.getString("diff.traditional.oneline"),m_rb.getString("diff.traditional.lines")}; double[] choiceLimits={1,2}; MessageFormat fmt=new MessageFormat(""); fmt.setLocale(WikiContext.getLocale(m_context)); ChoiceFormat cfmt=new ChoiceFormat(choiceLimits,choiceString); fmt.applyPattern(type); Format[] formats={NumberFormat.getInstance(),cfmt,NumberFormat.getInstance()}; fmt.setFormats(formats); Object[] params={changed.first() + 1,changed.size(),changed.size()}; m_result.append(fmt.format(params)); m_result.append(CSS_DIFF_CLOSE); }
Example 15
From project sojo, under directory /src/main/java/net/sf/sojo/common/.
Source file: ObjectUtil.java
23
public void addFormatterForType(Format pvFormat,Class<?> pvType){ simpleFormatConversion.addFormatter(pvType,pvFormat); if (getConverter().getConversionHandler().containsConversion(simpleFormatConversion) == false) { getConverter().addConversion(simpleFormatConversion); } }
Example 16
From project spring-data-mongodb, under directory /spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/.
Source file: CustomConversionsUnitTests.java
23
@Test @SuppressWarnings("unchecked") public void findsBasicReadAndWriteConversions(){ CustomConversions conversions=new CustomConversions(Arrays.asList(FormatToStringConverter.INSTANCE,StringToFormatConverter.INSTANCE)); assertThat(conversions.getCustomWriteTarget(Format.class,null),is(typeCompatibleWith(String.class))); assertThat(conversions.getCustomWriteTarget(String.class,null),is(nullValue())); assertThat(conversions.hasCustomReadTarget(String.class,Format.class),is(true)); assertThat(conversions.hasCustomReadTarget(String.class,Locale.class),is(false)); }
Example 17
From project spring-data-mongodb, under directory /spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/.
Source file: CustomConversionsUnitTests.java
23
@Test public void populatesConversionServiceCorrectly(){ GenericConversionService conversionService=new DefaultConversionService(); assertThat(conversionService.canConvert(String.class,UUID.class),is(false)); CustomConversions conversions=new CustomConversions(Arrays.asList(StringToFormatConverter.INSTANCE)); conversions.registerConvertersIn(conversionService); assertThat(conversionService.canConvert(String.class,Format.class),is(true)); }
Example 18
From project wayback, under directory /wayback-core/src/main/java/org/archive/wayback/util/.
Source file: StringFormatter.java
23
public MessageFormat getFormat(String pattern){ MessageFormat format=formats.get(pattern); if (format == null) { format=new MessageFormat(pattern,locale); Format[] subFormats=format.getFormats(); if (subFormats != null) { for ( Format subFormat : subFormats) { if (subFormat instanceof DateFormat) { DateFormat subDateFormat=(DateFormat)subFormat; subDateFormat.setTimeZone(TZ_UTC); } } } formats.put(pattern,format); } return format; }
Source: http://www.javased.com/?api=java.text.Format
0 Response to "Java Text Format Class Example"
Post a Comment