Hi there
This is what I use:
/**
* Parse the datestring into a valid date then format into a
different date in the outputformat
* If DateTime is empty then take current date
* <xsl:variable name="mydate"
select="java:FormatDate('','yyyy-MM-dd HH:mm:ss.SSS','yyyyMMddHHmmss')"/>
*/
public static String FormatDate(String DateTime, String InputFormat,
String OutputFormat)
{
if (DateTime==null)
{
try{
//InputFormat = new
SimpleDateFormat().toPattern();
InputFormat = "EEE MMM dd kk:mm:ss
z yyyy";
// Tue Nov 13 15:36:41 GMT+02:00 2001
DateTime = new
SimpleDateFormat(InputFormat).parse(new Date().toString()).toString();
}
catch (ParseException pe)
{
return pe.toString();
}
} else {
if (DateTime.length()==0)
{
try{
//InputFormat = new
SimpleDateFormat().toPattern();
//InputFormat =
((SimpleDateFormat)SimpleDateFormat.getDateTimeInstance()).toPattern();
//InputFormat =
DateFormat.getDateInstance().toPattern();
InputFormat = "EEE MMM dd
kk:mm:ss z yyyy";
// Tue Nov 13 15:36:41 GMT+02:00
2001
DateTime = new
SimpleDateFormat(InputFormat).parse(Calendar.getInstance().getTime().toStrin
g()).toString();
}
catch (ParseException pe)
{
return pe.toString();
}
}
}
// Specify SimpleDateFormatter in the specified date format
SimpleDateFormat df = new SimpleDateFormat(InputFormat);
try{
// Parse with SimpleDateFormatter in the specified
date format
Date d = df.parse(DateTime);
// Reformat in new format
SimpleDateFormat dfout = new
SimpleDateFormat(OutputFormat);
return dfout.format(d);
}
catch (ParseException pe)
{
return pe.toString();
}
}
Kind regards
Jo van der Merwe-----Original Message----- From: Keen Tim [mailto:[EMAIL PROTECTED]] Sent: 14 November 2001 07:22 To: [EMAIL PROTECTED] Subject: format-date() extension Has anyone done any work towards this? I have a need for it and therefore I'm going to do it, but being new to Java I don't expect it to be a brilliant piece of work. My job would certainly be easier if I could piggy-back off the work that somebody else has already done, even if it's only thoughts that they have or once had. I'm happy to contribute my work to the list and hopefully I'll receive constructive criticism. Cheers Tim ************************************************************************ The information in this e-mail together with any attachments is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any form of review, disclosure, modification, distribution and/or publication of this e-mail message is prohibited. If you have received this message in error, you are asked to inform the sender as quickly as possible and delete this message and any copies of this message from your computer and/or your computer system network. ************************************************************************
<<attachment: winmail.dat>>
