Java Code Examples for java.text.SimpleDateFormat#setDateFormatSymbols()
The following examples show how to use
java.text.SimpleDateFormat#setDateFormatSymbols() .
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: SimpleDateFormatTest.java From j2objc with Apache License 2.0 | 6 votes |
public void test_setDateFormatSymbolsLjava_text_DateFormatSymbols() { // Test for method void // java.text.SimpleDateFormat.setDateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat f1 = new SimpleDateFormat("a"); DateFormatSymbols symbols = new DateFormatSymbols(); symbols.setAmPmStrings(new String[] { "morning", "night" }); f1.setDateFormatSymbols(symbols); DateFormatSymbols newSym = f1.getDateFormatSymbols(); assertTrue("Set incorrectly", newSym.equals(symbols)); assertTrue("Not a clone", f1.getDateFormatSymbols() != symbols); String result = f1.format(new GregorianCalendar(1999, Calendar.JUNE, 12, 3, 0).getTime()); assertEquals("Incorrect symbols used", "morning", result); symbols.setEras(new String[] { "before", "after" }); assertTrue("Identical symbols", !f1.getDateFormatSymbols().equals(symbols)); try { f1.setDateFormatSymbols(null); fail(); } catch (NullPointerException expected) { } }
Example 2
Source File: DateFieldType.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public Object getDesignValue( final ExpressionRuntime runtime, final ReportElement element ) { Object formatStringRaw = element.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FORMAT_STRING ); final Object staticValue = ElementTypeUtils.queryStaticValue( element ); if ( staticValue instanceof Date ) { if ( formatStringRaw == null ) { // return the default to-string behavior of java.util.Date formatStringRaw = DEFAULT_FORMAT; } final Locale locale = runtime.getResourceBundleFactory().getLocale(); final TimeZone timeZone = runtime.getResourceBundleFactory().getTimeZone(); final SimpleDateFormat dateFormat = new SimpleDateFormat( String.valueOf( formatStringRaw ), locale ); dateFormat.setDateFormatSymbols( new DateFormatSymbols( locale ) ); dateFormat.setTimeZone( timeZone ); return rotate( element, dateFormat.format( staticValue ), runtime ); } final Object value = ElementTypeUtils.queryFieldName( element ); return rotate( element, value != null ? value : getId(), runtime ); }
Example 3
Source File: BasalChart.java From xDrip with GNU General Public License v3.0 | 5 votes |
static private Axis chartXAxis(int size) { final Axis xAxis = new Axis(); xAxis.setAutoGenerated(false); xAxis.setHasTiltedLabels(true); xAxis.setTiltAngle(-90f); xAxis.setMaxLabelChars(7); SimpleDateFormat sdf = new SimpleDateFormat(DateFormat.is24HourFormat(xdrip.getAppContext()) ? "HH:mm" : "a h:mm"); DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); // OVERRIDE SOME symbols WHILE RETAINING OTHERS symbols.setAmPmStrings(new String[] { "a", "p" }); sdf.setDateFormatSymbols(symbols); final java.text.DateFormat timeFormat = sdf; timeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(JoH.tsl()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); xAxis.setAutoGenerated(false); // TODO make this a better am/pm/24 hour thingy by dividing a day down? DST??? how does that work?? - done on load of value? List<AxisValue> axisValues = new ArrayList<>(); final int step = size / segments; final long dayStartMs = calendar.getTimeInMillis(); final long increment = Constants.DAY_IN_MS / segments; for (int i = 0; i < size; i = i + step) { calendar.setTimeInMillis(dayStartMs + i*increment); axisValues.add(new AxisValue(i / step, timeFormat.format(calendar.getTimeInMillis()).toCharArray())); } xAxis.setValues(axisValues); return xAxis; }
Example 4
Source File: BasalChart.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
static private Axis chartXAxis(int size) { final Axis xAxis = new Axis(); xAxis.setAutoGenerated(false); xAxis.setHasTiltedLabels(true); xAxis.setTiltAngle(-90f); xAxis.setMaxLabelChars(7); SimpleDateFormat sdf = new SimpleDateFormat(DateFormat.is24HourFormat(xdrip.getAppContext()) ? "HH:mm" : "a h:mm"); DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); // OVERRIDE SOME symbols WHILE RETAINING OTHERS symbols.setAmPmStrings(new String[] { "a", "p" }); sdf.setDateFormatSymbols(symbols); final java.text.DateFormat timeFormat = sdf; timeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(JoH.tsl()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); xAxis.setAutoGenerated(false); // TODO make this a better am/pm/24 hour thingy by dividing a day down? DST??? how does that work?? - done on load of value? List<AxisValue> axisValues = new ArrayList<>(); final int step = size / segments; final long dayStartMs = calendar.getTimeInMillis(); final long increment = Constants.DAY_IN_MS / segments; for (int i = 0; i < size; i = i + step) { calendar.setTimeInMillis(dayStartMs + i*increment); axisValues.add(new AxisValue(i / step, timeFormat.format(calendar.getTimeInMillis()).toCharArray())); } xAxis.setValues(axisValues); return xAxis; }
Example 5
Source File: MPXJBaseFormat.java From mpxj with GNU Lesser General Public License v2.1 | 5 votes |
/** * Allows the AM/PM text to be set. * * @param am AM text * @param pm PM text */ public void setAmPmText(String am, String pm) { for (SimpleDateFormat format : m_formats) { DateFormatSymbols symbols = format.getDateFormatSymbols(); symbols.setAmPmStrings(new String[] { am, pm }); format.setDateFormatSymbols(symbols); } }
Example 6
Source File: ThreadSafeDateFormatter.java From AndroidCommons with Apache License 2.0 | 5 votes |
protected SimpleDateFormat initialValue() { final Locale locale = ThreadSafeDateFormatter.this.locale == null ? Locale.getDefault() : ThreadSafeDateFormatter.this.locale; final SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale); if (tz != null) { formatter.setTimeZone(tz); } if (symbols != null) { formatter.setDateFormatSymbols(symbols); } return formatter; }
Example 7
Source File: DateFormatSymbolsTest.java From j2objc with Apache License 2.0 | 4 votes |
private String formatDate(Locale l, String fmt, DateFormatSymbols dfs) { SimpleDateFormat sdf = new SimpleDateFormat(fmt, l); sdf.setDateFormatSymbols(dfs); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(new Date(0)); }
Example 8
Source File: ConvertToDateExpression.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Parses the value read from the column specified by the given field-name and tries to parse it into a Date using the * given SimpleDateFormat-pattern. * * @return the value of the function. */ public Object getValue() { final DataRow dataRow = getDataRow(); // get the row directly as a Number final Object o = dataRow.get( field ); // check if that thing is a Number if ( o instanceof Date ) { return o; } // get a string and convert try { Locale localeUsed = locale; if ( localeUsed == null ) { localeUsed = getResourceBundleFactory().getLocale(); } final DateFormat format; if ( dateFormat == null || ObjectUtilities.equal( localeUsed, lastLocale ) == false ) { final String formatString = getFormat(); if ( formatString == null || formatString.length() == 0 ) { format = DateFormat.getDateInstance( DateFormat.DEFAULT, localeUsed ); dateFormat = format; lastLocale = localeUsed; } else { final SimpleDateFormat sformat = new SimpleDateFormat( formatString ); if ( locale != null ) { sformat.setDateFormatSymbols( new DateFormatSymbols( locale ) ); } else { final ResourceBundleFactory factory = getResourceBundleFactory(); sformat.setDateFormatSymbols( new DateFormatSymbols( factory.getLocale() ) ); } format = sformat; dateFormat = sformat; lastLocale = localeUsed; } } else { format = dateFormat; } if ( ObjectUtilities.equal( timeZone, lastTimeZone ) == false ) { lastTimeZone = timeZone; format.setTimeZone( timeZone ); } return format.parse( String.valueOf( o ) ); } catch ( ParseException e ) { return null; } }