下面列出了java.text.Format#format ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
@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;
}
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";
}
/**
* 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;
}
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;
}
@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");
}
@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");
}
@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");
}
@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");
}
public static String SYSDATE(String str) {
Format format = new SimpleDateFormat(str);
String st = format.format(new Date());
return st;
}
@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");
}
@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);
}
/**
* 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;
}
@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");
}
@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");
}
@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");
}
@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);
}
@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");
}
/**
* 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
}
/**
* <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);
}