Java Code Examples for java.text.Format#format()

The following examples show how to use java.text.Format#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TeDhenat.java    From Automekanik with GNU General Public License v3.0 6 votes vote down vote up
public void mbush(){
    try {
        String sql = "select * from Punet where konsumatori = '" + e.getText() + "' order by id asc";
        Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        ObservableList<punetTbl> data = FXCollections.observableArrayList();
        Format format = new SimpleDateFormat("dd/MM/yyyy");
        String s = "";
        while (rs.next()){
            s = format.format(rs.getDate("data"));
            data.add(new punetTbl(rs.getInt("id"), rs.getString("lloji"),
                    s, rs.getFloat("qmimi"), rs.getString("pershkrimi"), rs.getString("kryer"), rs.getString("makina")));
        }
        table.getItems().clear();
        table.setItems(data);
        conn.close();
    }catch (Exception ex){
        ex.printStackTrace();
    }
}
 
Example 2
Source File: LogFileHandler.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
private static String getPattern() {
	final Date date = new Date();
	final Format fileDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
	final String pathLogFileFolder = Configuration.getPathLogFileFolder();
	final Path logFileFolder = Paths.get(pathLogFileFolder);
	if (Files.notExists(logFileFolder)) {
		try {
			Files.createDirectories(logFileFolder);
		} catch (IOException e) {
			Logger.getLogger(LogFileHandler.class.getName()).log(Level.SEVERE, "Could not create log file folder",
					e);
		}
	}
	return pathLogFileFolder + "mp_" + fileDateFormat.format(date) + ".log";
}
 
Example 3
Source File: TCKDateTimeFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_format() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example 4
Source File: TCKDateTimeFormatter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_format() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example 5
Source File: FormatFilter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the formatted string. The value is read using the data source given and formated using the formatter of
 * this object. The formating is guaranteed to completly form the object to an string or to return the defined
 * NullValue.
 * <p/>
 * If format, datasource or object are null, the NullValue is returned.
 *
 * @param runtime
 *          the expression runtime that is used to evaluate formulas and expressions when computing the value of this
 *          filter.
 * @param element
 * @return The formatted value.
 */
public Object getValue( final ExpressionRuntime runtime, final ReportElement element ) {
  final Format f = getFormatter();
  if ( f == null ) {
    return getNullValue();
  }

  final DataSource ds = getDataSource();
  if ( ds == null ) {
    return getNullValue();
  }

  final Object o = ds.getValue( runtime, element );
  if ( o == null ) {
    return getNullValue();
  }

  if ( cachedResult != null && ( cachedFormat != f ) && ObjectUtilities.equal( cachedValue, o ) ) {
    return cachedResult;
  }

  try {
    cachedResult = f.format( o );
  } catch ( IllegalArgumentException e ) {
    cachedResult = getNullValue();
  }

  cachedFormat = f;
  cachedValue = o;
  return cachedResult;
}
 
Example 6
Source File: SimpleDataPoint.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String toString() {
  Format mzFormat = MZmineCore.getConfiguration().getMZFormat();
  Format intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
  String str =
      "m/z: " + mzFormat.format(mz) + ", intensity: " + intensityFormat.format(intensity);
  return str;
}
 
Example 7
Source File: UpgradeUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static final String getSysCatalogSnapshotName(long currentSystemTableTimestamp) {
    String tableString = SYSTEM_CATALOG_NAME;
    Format formatter = new SimpleDateFormat("yyyyMMddHHmmss");
    String date = formatter.format(new Date(EnvironmentEdgeManager.currentTimeMillis()));
    String upgradingFrom = getVersion(currentSystemTableTimestamp);
    return "SNAPSHOT_" + tableString + "_" + upgradingFrom + "_TO_" + CURRENT_CLIENT_VERSION + "_" + date;
}
 
Example 8
Source File: DataFormatter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Formats the given raw cell value, based on the supplied
 *  format index and string, according to excel style rules.
 * @see #formatCellValue(Cell)
 */
public String formatRawCellContents(double value, int formatIndex, String formatString, boolean use1904Windowing) {
    localeChangedObservable.checkForLocaleChange();
    
    // Is it a date?
    if(DateUtil.isADateFormat(formatIndex,formatString)) {
        if(DateUtil.isValidExcelDate(value)) {
            Format dateFormat = getFormat(value, formatIndex, formatString);
            if(dateFormat instanceof ExcelStyleDateFormatter) {
                // Hint about the raw excel value
                ((ExcelStyleDateFormatter)dateFormat).setDateToBeFormatted(value);
            }
            Date d = DateUtil.getJavaDate(value, use1904Windowing);
            return performDateFormatting(d, dateFormat);
        }
        // RK: Invalid dates are 255 #s.
        if (emulateCSV) {
            return invalidDateTimeString;
        }
    }
    
    // else Number
    Format numberFormat = getFormat(value, formatIndex, formatString);
    if (numberFormat == null) {
        return String.valueOf(value);
    }
    
    // When formatting 'value', double to text to BigDecimal produces more
    // accurate results than double to Double in JDK8 (as compared to
    // previous versions). However, if the value contains E notation, this
    // would expand the values, which we do not want, so revert to
    // original method.
    String result;
    final String textValue = NumberToTextConverter.toText(value);
    if (textValue.indexOf('E') > -1) {
        result = numberFormat.format(new Double(value));
    }
    else {
        result = numberFormat.format(new BigDecimal(textValue));
    }
    // Complete scientific notation by adding the missing +.
    if (result.indexOf('E') > -1 && !result.contains("E-")) {
        result = result.replaceFirst("E", "E+");
    }
    return result;
}
 
Example 9
Source File: TCKDateTimeFormatter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_toFormat_Query_format() throws Exception {
    Format format = BASIC_FORMATTER.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example 10
Source File: TCKDateTimeFormatter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_toFormat_format_null() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format(null);
}
 
Example 11
Source File: TCKDateTimeFormatter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=IllegalArgumentException.class)
public void test_toFormat_format_notTemporal() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format("Not a Temporal");
}
 
Example 12
Source File: TCKDateTimeFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_toFormat_Query_format() throws Exception {
    Format format = BASIC_FORMATTER.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example 13
Source File: TCKDateTimeFormatter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_toFormat_Query_format() throws Exception {
    Format format = BASIC_FORMATTER.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example 14
Source File: TCKDateTimeFormatter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_toFormat_format_null() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format(null);
}
 
Example 15
Source File: TCKDateTimeFormatter.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void test_toFormat_Query_format() throws Exception {
    Format format = BASIC_FORMATTER.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example 16
Source File: DateUtils.java    From momo-cloud-permission with Apache License 2.0 4 votes vote down vote up
public static String SYSDATE(String str) {
    Format format = new SimpleDateFormat(str);
    String st = format.format(new Date());
    return st;
}
 
Example 17
Source File: TCKDateTimeFormatter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=IllegalArgumentException.class)
public void test_toFormat_format_notTemporal() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format("Not a Temporal");
}
 
Example 18
Source File: TestDateTimeFormatter.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(expectedExceptions=IllegalArgumentException.class)
public void test_toFormat_format_notCalendrical() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format("Not a Calendrical");
}
 
Example 19
Source File: DataFormatter.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the formatted value of an Excel number as a <tt>String</tt>
 * based on the cell's <code>DataFormat</code>. Supported formats include
 * currency, percents, decimals, phone number, SSN, etc.:
 * "61.54%", "$100.00", "(800) 555-1234".
 * <p>
 * Format comes from either the highest priority conditional format rule with a
 * specified format, or from the cell style.
 * 
 * @param cell The cell
 * @param cfEvaluator if available, or null
 * @return a formatted number string
 */
private String getFormattedNumberString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {

    Format numberFormat = getFormat(cell, cfEvaluator);
    double d = cell.getNumericCellValue();
    if (numberFormat == null) {
        return String.valueOf(d);
    }
    String formatted = numberFormat.format(new Double(d));
    return formatted.replaceFirst("E(\\d)", "E+$1"); // to match Excel's E-notation
}
 
Example 20
Source File: AbstractFormatValidator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Format a value with the specified <code>Format</code>.</p>
 *
 * @param value The value to be formatted.
 * @param formatter The Format to use.
 * @return The formatted value.
 */
protected String format(Object value, Format formatter) {
    return formatter.format(value);
}