List of usage examples for org.apache.commons.lang.time FastDateFormat getDateInstance
public static FastDateFormat getDateInstance(int style)
Gets a date formatter instance using the specified style in the default time zone and locale.
From source file:com.exxatools.monitoring.jmx.converters.CalendarConverter.java
protected FastDateFormat getDateFormat() { if (dateFormat == null) { dateFormat = FastDateFormat.getDateInstance(dateFormatStyle); } return dateFormat; }
From source file:edu.ku.brc.specify.tests.PreferenceTest.java
/** * Tests the Date formating/*from w w w . jav a 2 s . c o m*/ */ public void testSimpleDateFormat() { FastDateFormat fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.SHORT); SimpleDateFormat df = new SimpleDateFormat(fastDateFormat.getPattern()); log.info(df.toPattern()); log.info(df.format(new Date())); fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM); df = new SimpleDateFormat(fastDateFormat.getPattern()); log.info(df.toPattern()); log.info(df.format(new Date())); fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.LONG); df = new SimpleDateFormat(fastDateFormat.getPattern()); log.info(df.toPattern()); log.info(df.format(new Date())); }
From source file:usingflume.ch05.HeaderAndBodyIndexRequestBuilderFactoryTest.java
@Test public void testPrepareIndexRequest() throws Exception { ElasticSearchIndexRequestBuilderFactory factory = new HeaderAndBodyIndexRequestBuilderFactory(); // There is a small race condition here. // If you start the test before midnight and continue after, // then this might fail because the date has changed. FastDateFormat date = FastDateFormat.getDateInstance(FastDateFormat.FULL); String suffix = date.format(System.currentTimeMillis()); final Client client = NodeBuilder.nodeBuilder().client(true).local(true).node().client(); ctx.put("writeHeaders", "true"); factory.configure(ctx);//from www .ja v a2 s. c o m for (int i = 0; i < 10; i++) { final String iStr = String.valueOf(i); final String BODY_STR = TEST_EVENT_PREFIX + iStr; final String IDX_NAME = IDX_PREFIX + iStr; final String IDX_TYPE = IDX_TYPE_PREFIX + iStr; final Map<String, String> headers = Maps.newHashMap(); headers.put(EVENT_ID, iStr); final Event e = EventBuilder.withBody(BODY_STR.getBytes(Charsets.UTF_8), headers); final IndexRequestBuilder request = factory.createIndexRequest(client, IDX_NAME, IDX_TYPE, e); final Map src = request.request().sourceAsMap(); Assert.assertEquals(src.get(EVENT_ID), iStr); Assert.assertEquals(src.get("body"), BODY_STR); Assert.assertTrue(request.request().type().startsWith(IDX_TYPE)); Assert.assertTrue(request.request().index().startsWith(IDX_NAME)); Assert.assertTrue(request.request().index().endsWith(suffix)); } ctx.put("writeHeaders", "false"); factory.configure(ctx); final IndexRequestBuilder request = factory.createIndexRequest(client, IDX_PREFIX, IDX_TYPE_PREFIX, EventBuilder.withBody("test data", Charsets.UTF_8)); byte[] body = request.request().source().array(); Assert.assertEquals("test data", new String(body, Charsets.UTF_8)); Assert.assertTrue(request.request().type().startsWith(IDX_TYPE_PREFIX)); Assert.assertTrue(request.request().index().startsWith(IDX_PREFIX)); Assert.assertTrue(request.request().index().endsWith(suffix)); }