|
. |
TodaysDate is a small Java handler that returns a text string of the form "Thursday 18 June 1998", as requested by a client.
package client.someone.handler.misc;
import java.util.Hashtable;
import java.util.Vector;
import organic.servlet.broker.*;
import organic.client.feld.Stuff;
import java.util.Calendar ;
import java.text.SimpleDateFormat ;
import java.text.FieldPosition ;
// Returns "Thursday, 18th June 1998"
public class TodaysDate implements HandlerInterface {
public Object handleToken(String tokenName,
Hashtable args,
Request request)
throws HandlerException
{
try {
String[] thArray = new String[] {
"th", "st","nd","rd","th","th","th","th","th","th","th",
"th","th","th","th","th","th","th","th","th","th",
"st","nd","rd","th","th","th","th","th","th","th","st" };
Calendar c = Calendar.getInstance() ;
SimpleDateFormat f = new SimpleDateFormat( "EEEE, MMMM dd" ) ;
SimpleDateFormat g = new SimpleDateFormat( "yyyy" ) ;
SimpleDateFormat h = new SimpleDateFormat( "dd" ) ;
int dim = (new Integer(h.format( c.getTime() ))).intValue() ;
return f.format( c.getTime()) + thArray[dim] + " " + g.format( c.getTime()) ;
} catch (Exception e) { throw new HandlerException(e); }
}
}
|
|
This page is copyrighted 1993-2006 by Michael 'Mickey' Sattler, some rights reserved via the Creative Commons License. Questions and comments? Send email to the Geek Times Webmaster. (Domain and web content hosting at 1and1.)
|
|