Java Code Examples for java.text.DateFormat.getInstance()

The following are Jave code examples for showing how to use getInstance() of the java.text.DateFormat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: neoscada   File: XAxisDynamicRenderer.java   Source Code and License Vote up 6 votes
protected DateFormat createFormatInstance ( final long timeRange )
{
    if ( hasFormat () )
    {
        try
        {
            return new SimpleDateFormat ( this.format );
        }
        catch ( final IllegalArgumentException e )
        {
            return DateFormat.getInstance ();
        }
    }
    else
    {
        return Helper.makeFormat ( timeRange );
    }
}
 
Example 2
Project: OSWf-OSWorkflow-fork   File: FileTest.java   Source Code and License Vote up 6 votes
private void verifyTheProperties(PropertySet propertySet) {

        DateFormat df = DateFormat.getInstance();
        
        assertEquals(true, propertySet.getBoolean("testBoolean"));
        assertEquals(new String("value1".getBytes()), new String(propertySet.getData("testData")));
        assertEquals(df.format(now), df.format(propertySet.getDate("testDate")));
        assertEquals(10.245, propertySet.getDouble("testDouble"), 0);
        assertEquals(7, propertySet.getInt("testInt"));
        assertEquals(100000, propertySet.getLong("testLong"));
        assertEquals(new TestObject(1), propertySet.getObject("testObject"));
        assertEquals(embeddedProps, propertySet.getProperties("testProperties"));
        assertEquals("value1", propertySet.getString("testString"));
        assertEquals(TEXT_VALUE, propertySet.getText("testText"));
        assertNotNull(propertySet.getXML("testXml"));
        
    }
 
Example 3
Project: parabuild-ci   File: StandardCategoryLabelGeneratorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    StandardCategoryLabelGenerator g1 = new StandardCategoryLabelGenerator(
        "{2}", DateFormat.getInstance()
    );
    StandardCategoryLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        g2 = (StandardCategoryLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);

}
 
Example 4
Project: parabuild-ci   File: IntervalCategoryLabelGeneratorTests.java   Source Code and License Vote up 6 votes
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    IntervalCategoryLabelGenerator g1
        = new IntervalCategoryLabelGenerator("{3} - {4}", DateFormat.getInstance());
    IntervalCategoryLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        g2 = (IntervalCategoryLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);

}
 
Example 5
Project: SeeLog   File: Logger.java   Source Code and License Vote up 5 votes
public static String getDate(int type, String t) {
    String resultValue = "";
    try {
        Calendar ca = Calendar.getInstance();
        ca.add(Calendar.DATE, type);
        SimpleDateFormat df = (SimpleDateFormat) DateFormat.getInstance();
        df.applyPattern(t);
        resultValue = df.format(ca.getTime());
    } catch (Exception e) {
        Log.i("Logger", "e getDate");
    }

    return resultValue;
}
 
Example 6
Project: Lucid2.0   File: GMCommand.java   Source Code and License Vote up 5 votes
@Override
public int execute(MapleClient c, String[] splitted) {
    if (splitted.length < 4) {
        c.getPlayer().dropMessage(6, "Tempban [name] [REASON] [hours]");
        StringBuilder s = new StringBuilder("Tempban reasons: ");
        for (int i = 0; i < types.length; i++) {
            s.append(i + 1).append(" - ").append(types[i]).append(", ");
        }
        c.getPlayer().dropMessage(6, s.toString());
        return 0;
    }
    final MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
    final int reason = Integer.parseInt(splitted[2]);
    final int numHour = Integer.parseInt(splitted[3]);

    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, numHour);
    final DateFormat df = DateFormat.getInstance();

    if (victim == null || reason < 0 || reason >= types.length) {
        c.getPlayer().dropMessage(6, "Unable to find character or reason was not valid, type tempban to see reasons");
        return 0;
    }
    victim.tempban("Temp banned by " + c.getPlayer().getName() + " for " + types[reason] + " reason", cal, reason, ipBan);
    c.getPlayer().dropMessage(6, "The character " + splitted[1] + " has been successfully tempbanned till " + df.format(cal.getTime()));
    return 1;
}
 
Example 7
Project: aos-MediaLib   File: HttpCache.java   Source Code and License Vote up 5 votes
private boolean fileNeedsRefresh(File f) {
    if (f.length() < 1) return true;
    if (mCacheTimeOut > 0) {
        if ((f.lastModified() + mCacheTimeOut) < System.currentTimeMillis()) {
            if (DBG) {
                DateFormat fmt = DateFormat.getInstance();
                Log.d(TAG, "File " + f.getPath() + " too old f:" + fmt.format(new Date(f.lastModified())) + " now:" + fmt.format(new Date()));
            }
            return true;
        }
    }
    return false;
}
 
Example 8
Project: L2J-Global   File: TopicBBSManager.java   Source Code and License Vote up 4 votes
private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index)
{
	forum.vload();
	final StringBuilder html = new StringBuilder(2000);
	html.append("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=2 bgcolor=888888 width=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=415 align=center>&$413;</td><td FIXWIDTH=120 align=center></td><td FIXWIDTH=70 align=center>&$418;</td></tr></table>");
	final DateFormat dateFormat = DateFormat.getInstance();
	
	for (int i = 0, j = getMaxID(forum) + 1; i < (12 * index); j--)
	{
		if (j < 0)
		{
			break;
		}
		final Topic t = forum.getTopic(j);
		if (t != null)
		{
			if (i++ >= (12 * (index - 1)))
			{
				html.append("<table border=0 cellspacing=0 cellpadding=5 WIDTH=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=415><a action=\"bypass _bbsposts;read;" + forum.getID() + ";" + t.getID() + "\">" + t.getName() + "</a></td><td FIXWIDTH=120 align=center></td><td FIXWIDTH=70 align=center>" + dateFormat.format(new Date(t.getDate())) + "</td></tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
			}
		}
	}
	
	html.append("<br><table width=610 cellspace=0 cellpadding=0><tr><td width=50><button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"></td><td width=510 align=center><table border=0><tr>");
	
	if (index == 1)
	{
		html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
	}
	else
	{
		html.append("<td><button action=\"bypass _bbstopics;read;" + forum.getID() + ";" + (index - 1) + "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
	}
	
	int nbp = forum.getTopicSize() / 8;
	if ((nbp * 8) != ClanTable.getInstance().getClanCount())
	{
		nbp++;
	}
	for (int i = 1; i <= nbp; i++)
	{
		if (i == index)
		{
			html.append("<td> " + i + " </td>");
		}
		else
		{
			html.append("<td><a action=\"bypass _bbstopics;read;" + forum.getID() + ";" + i + "\"> " + i + " </a></td>");
		}
	}
	if (index == nbp)
	{
		html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
	}
	else
	{
		html.append("<td><button action=\"bypass _bbstopics;read;" + forum.getID() + ";" + (index + 1) + "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
	}
	
	html.append("</tr></table> </td> <td align=right><button value = \"&$421;\" action=\"bypass _bbstopics;crea;" + forum.getID() + "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr> <td></td><td align=center><table border=0><tr><td></td><td><edit var = \"Search\" width=130 height=11></td><td><button value=\"&$420;\" action=\"Write 5 -2 0 Search _ _\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td> </tr></table> </td></tr></table><br><br><br></center></body></html>");
	CommunityBoardHandler.separateAndSend(html.toString(), activeChar);
}
 
Example 9
Project: ChronoBike   File: DateUtil.java   Source Code and License Vote up 4 votes
/**
 * Initialise la date
 */
public void setDate(String cs) 
{
	DateFormat df = DateFormat.getInstance() ;
	Date date ;
	try
	{
		date = df.parse(cs);
		calendar.setTime(date);
	} 
	catch (ParseException e)
	{
		e.printStackTrace();
	}
}
 
Example 10
Project: parabuild-ci   File: HighLowItemLabelGenerator.java   Source Code and License Vote up 4 votes
/**
 * Creates an item label generator using the default date and number formats.
 */
public HighLowItemLabelGenerator() {
    this(DateFormat.getInstance(), NumberFormat.getInstance());
}
 
Example 11
Project: parabuild-ci   File: StandardXYToolTipGenerator.java   Source Code and License Vote up 2 votes
/**
 * Returns a tool tip generator that formats the x-values as dates and the 
 * y-values as numbers.
 * 
 * @return A tool tip generator (never <code>null</code>).
 */
public static StandardXYToolTipGenerator getTimeSeriesInstance() {
    return new StandardXYToolTipGenerator(
        DEFAULT_TOOL_TIP_FORMAT, DateFormat.getInstance(), NumberFormat.getInstance()
    );
}
 
Example 12
Project: parabuild-ci   File: StandardXYToolTipGenerator.java   Source Code and License Vote up 2 votes
/**
 * Returns a tool tip generator that formats the x-values as dates and the 
 * y-values as numbers.
 * 
 * @return A tool tip generator (never <code>null</code>).
 */
public static StandardXYToolTipGenerator getTimeSeriesInstance() {
    return new StandardXYToolTipGenerator(DEFAULT_TOOL_TIP_FORMAT, 
            DateFormat.getInstance(), NumberFormat.getInstance());
}
 
Example 13
Project: parabuild-ci   File: HighLowItemLabelGenerator.java   Source Code and License Vote up 2 votes
/**
 * Creates an item label generator using the default date and number 
 * formats.
 */
public HighLowItemLabelGenerator() {
    this(DateFormat.getInstance(), NumberFormat.getInstance());
}