You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by JoseBovet <jo...@gmail.com> on 2007/11/07 22:32:52 UTC
I need help with date format
hi guy's
I have a problem with a date format,
I need format a Integer to Date or Integer to String
a example:
int number1 20070101 to date format (01-01-2007)
or
int number1 20070101 to String format (01-01-2007)
number1 is get for method in a DB oracle!!!
greetings°
--
View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: I need help with date format
Posted by Nathan Bubna <nb...@gmail.com>.
On Nov 13, 2007 6:57 AM, JoseBovet <jo...@gmail.com> wrote:
>
> thanks guy's
> I have tried to follow your's steps steps but nothing, I'm trying with the
> following:
>
> Class FichaSDDCTRL, I am using SpringFramework
>
> public class FichaSddCtrl implements Controller {
>
> private SddService sdd_service;
>
> public void setSdd_service(SddService sdd_service) {
> this.sdd_service = sdd_service;
> }
>
>
> /***************************************************************************
> * Método para evaluar id del sdd
> *
> * @param Numero
> * a evaluar
> * @return Boolean
> */
> public static Boolean isNumeric(String aEvaluar) {
>
> try {
> Integer.parseInt(aEvaluar);
> return true;
> } catch (NumberFormatException nfe) {
> return false;
> }
>
> }
>
> /** Logger for this class and subclasses */
> protected final Log logger = LogFactory.getLog(getClass());
>
> public ModelAndView handleRequest(HttpServletRequest arg0,
> HttpServletResponse arg1) throws Exception {
>
> Map model = new HashMap();
> // TODO Auto-generated method stub
>
> Integer id_sdd;
> Boolean esNumero;
> SdddetExample criterio = new SdddetExample();
> List<Sdddet> detalleList = new ArrayList<Sdddet>();
> Sddenc encabezado = new Sddenc();
>
> // llamo método isNumeric y le paso el id
> esNumero = isNumeric(arg0.getParameter("id"));
>
> // valido que no venga vacio y que el retorno del método isNumeric sea
> // true
> if (arg0.getParameter("id") != "" && esNumero == true) {
>
> id_sdd = Integer.parseInt(arg0.getParameter("id"));
>
> encabezado = sdd_service.selectEncabezadoSddEncByIdSdd(id_sdd);
> detalleList = sdd_service.selectDetalleSddByIdSdd(id_sdd);
>
>
> DateTool datetool = new DateTool();
>
>
> model.put("date", datetool);
> model.put("encabezado", encabezado);
> model.put("detalleList", detalleList);
> }
>
>
>
>
> return new ModelAndView("ficha_sdd", model);
> }
>
> }
>
> In velocity ficha.vm:
>
> #set($fechaVenta =$!encabezado.getFectra()))
> $!date.format('yyyy-MM-dd',$fechaVenta)
>
>
> in the vm page the value of fechaVenta is 1970-01-01
> but the value of $!encabezado.getFectra() is 20071112
>
> I need help??? :(
try this:
$date.format('yyyy-MM-dd', $date.toDate('yyyyMMdd', "$encabezado.fectra"))
the trick is that your 20071112 integer is not an automatically
recognized date format, so you need to turn it into a string and tell
DateTool.toDate() what format it is in. then you can pass the
resulting Date object into the format() method and have DateTool
reformat it into the form you want.
but honestly, you will get better performance on this routine if you
write your own MyDateTool class (which could extend DateTool if you
wanted) with a function that does all of this automatically. this
would simplify your template into:
$date.reformat($encabezado.fectra)
>
>
>
>
>
>
>
> Nathan Bubna wrote:
> >
> > you can write a little helper tool to do it:
> >
> > public MyDateTool {
> > public Date format(int oracleDate) {
> > //TODO: the actual conversion here
> > }
> > }
> >
> > or use this one:
> > http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
> >
> > On 11/7/07, JoseBovet <jo...@gmail.com> wrote:
> >>
> >> hi guy's
> >>
> >>
> >> I have a problem with a date format,
> >> I need format a Integer to Date or Integer to String
> >> a example:
> >>
> >> int number1 20070101 to date format (01-01-2007)
> >> or
> >>
> >> int number1 20070101 to String format (01-01-2007)
> >>
> >> number1 is get for method in a DB oracle!!!
> >>
> >>
> >> greetings°
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
> >> Sent from the Velocity - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >> For additional commands, e-mail: user-help@velocity.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13727488
>
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: I need help with date format
Posted by JoseBovet <jo...@gmail.com>.
thanks guy's
I have tried to follow your's steps steps but nothing, I'm trying with the
following:
Class FichaSDDCTRL, I am using SpringFramework
public class FichaSddCtrl implements Controller {
private SddService sdd_service;
public void setSdd_service(SddService sdd_service) {
this.sdd_service = sdd_service;
}
/***************************************************************************
* Método para evaluar id del sdd
*
* @param Numero
* a evaluar
* @return Boolean
*/
public static Boolean isNumeric(String aEvaluar) {
try {
Integer.parseInt(aEvaluar);
return true;
} catch (NumberFormatException nfe) {
return false;
}
}
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
Map model = new HashMap();
// TODO Auto-generated method stub
Integer id_sdd;
Boolean esNumero;
SdddetExample criterio = new SdddetExample();
List<Sdddet> detalleList = new ArrayList<Sdddet>();
Sddenc encabezado = new Sddenc();
// llamo método isNumeric y le paso el id
esNumero = isNumeric(arg0.getParameter("id"));
// valido que no venga vacio y que el retorno del método isNumeric sea
// true
if (arg0.getParameter("id") != "" && esNumero == true) {
id_sdd = Integer.parseInt(arg0.getParameter("id"));
encabezado = sdd_service.selectEncabezadoSddEncByIdSdd(id_sdd);
detalleList = sdd_service.selectDetalleSddByIdSdd(id_sdd);
DateTool datetool = new DateTool();
model.put("date", datetool);
model.put("encabezado", encabezado);
model.put("detalleList", detalleList);
}
return new ModelAndView("ficha_sdd", model);
}
}
In velocity ficha.vm:
#set($fechaVenta =$!encabezado.getFectra()))
$!date.format('yyyy-MM-dd',$fechaVenta)
in the vm page the value of fechaVenta is 1970-01-01
but the value of $!encabezado.getFectra() is 20071112
I need help??? :(
Nathan Bubna wrote:
>
> you can write a little helper tool to do it:
>
> public MyDateTool {
> public Date format(int oracleDate) {
> //TODO: the actual conversion here
> }
> }
>
> or use this one:
> http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
>
> On 11/7/07, JoseBovet <jo...@gmail.com> wrote:
>>
>> hi guy's
>>
>>
>> I have a problem with a date format,
>> I need format a Integer to Date or Integer to String
>> a example:
>>
>> int number1 20070101 to date format (01-01-2007)
>> or
>>
>> int number1 20070101 to String format (01-01-2007)
>>
>> number1 is get for method in a DB oracle!!!
>>
>>
>> greetings°
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
>> Sent from the Velocity - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13727488
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: I need help with date format
Posted by JoseBovet <jo...@gmail.com>.
thanks guy's
I have tried to follow your's steps steps but nothing, I'm trying with the
following:
Class FichaSDDCTRL, I am using SpringFramework
public class FichaSddCtrl implements Controller {
private SddService sdd_service;
public void setSdd_service(SddService sdd_service) {
this.sdd_service = sdd_service;
}
/***************************************************************************
* Método para evaluar id del sdd
*
* @param Numero
* a evaluar
* @return Boolean
*/
public static Boolean isNumeric(String aEvaluar) {
try {
Integer.parseInt(aEvaluar);
return true;
} catch (NumberFormatException nfe) {
return false;
}
}
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
Map model = new HashMap();
// TODO Auto-generated method stub
Integer id_sdd;
Boolean esNumero;
SdddetExample criterio = new SdddetExample();
List<Sdddet> detalleList = new ArrayList<Sdddet>();
Sddenc encabezado = new Sddenc();
// llamo método isNumeric y le paso el id
esNumero = isNumeric(arg0.getParameter("id"));
// valido que no venga vacio y que el retorno del método isNumeric sea
// true
if (arg0.getParameter("id") != "" && esNumero == true) {
id_sdd = Integer.parseInt(arg0.getParameter("id"));
encabezado = sdd_service.selectEncabezadoSddEncByIdSdd(id_sdd);
detalleList = sdd_service.selectDetalleSddByIdSdd(id_sdd);
DateTool datetool = new DateTool();
model.put("date", datetool);
model.put("encabezado", encabezado);
model.put("detalleList", detalleList);
}
return new ModelAndView("ficha_sdd", model);
}
}
In velocity ficha.vm:
#set($fechaVenta =$!encabezado.getFectra()))
$!date.format('yyyy-MM-dd',$fechaVenta)
in the vm page the value of fechaVenta is 1970-01-01
but the value of $!encabezado.getFectra() is 20071112
I need help??? :(
Nathan Bubna wrote:
>
> you can write a little helper tool to do it:
>
> public MyDateTool {
> public Date format(int oracleDate) {
> //TODO: the actual conversion here
> }
> }
>
> or use this one:
> http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
>
> On 11/7/07, JoseBovet <jo...@gmail.com> wrote:
>>
>> hi guy's
>>
>>
>> I have a problem with a date format,
>> I need format a Integer to Date or Integer to String
>> a example:
>>
>> int number1 20070101 to date format (01-01-2007)
>> or
>>
>> int number1 20070101 to String format (01-01-2007)
>>
>> number1 is get for method in a DB oracle!!!
>>
>>
>> greetings°
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
>> Sent from the Velocity - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13727491
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: I need help with date format
Posted by Nathan Bubna <nb...@gmail.com>.
you can write a little helper tool to do it:
public MyDateTool {
public Date format(int oracleDate) {
//TODO: the actual conversion here
}
}
or use this one:
http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
On 11/7/07, JoseBovet <jo...@gmail.com> wrote:
>
> hi guy's
>
>
> I have a problem with a date format,
> I need format a Integer to Date or Integer to String
> a example:
>
> int number1 20070101 to date format (01-01-2007)
> or
>
> int number1 20070101 to String format (01-01-2007)
>
> number1 is get for method in a DB oracle!!!
>
>
> greetings°
>
>
>
> --
> View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: I need help with date format
Posted by JoseBovet <jo...@gmail.com>.
Thanks htila
public static String FormatoFechaEnc(int fecha) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdfa = new SimpleDateFormat("dd-MM-yyyy");
int idate = fecha;
String sdate = new String(idate + "");
java.util.Date ddate = sdf.parse(sdate, new ParsePosition(0));
return sdfa.format(ddate);
}
in the controller
nuevaFecha = General.FormatoFechaEnc(encabezado.getFectra());
model.put("nuevaFecha", nuevaFecha);
in the vm page
<td>$nuevaFecha</td>
it's works...
Thank you very much
rgs
htila tha wrote:
>
> Hi,
>
> Might not be good. But it works.
> SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
> SimpleDateFormat sdfa = new SimpleDateFormat("dd-MM-yyyy");
>
> int idate = 20071101;
> String sdate = new String(idate+"");
> java.util.Date ddate = sdf.parse(sdate, new ParsePosition(0));
> System.out.println(sdfa.format(ddate));
> rgds
>
> JoseBovet <jo...@gmail.com> wrote:
> hi guy's
>
>
> I have a problem with a date format,
> I need format a Integer to Date or Integer to String
> a example:
>
> int number1 20070101 to date format (01-01-2007)
> or
>
> int number1 20070101 to String format (01-01-2007)
>
> number1 is get for method in a DB oracle!!!
>
>
> greetings°
>
>
>
> --
> View this message in context:
> http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
--
View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13731949
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: I need help with date format
Posted by htila tha <au...@yahoo.com>.
Hi,
Might not be good. But it works.
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdfa = new SimpleDateFormat("dd-MM-yyyy");
int idate = 20071101;
String sdate = new String(idate+"");
java.util.Date ddate = sdf.parse(sdate, new ParsePosition(0));
System.out.println(sdfa.format(ddate));
rgds
JoseBovet <jo...@gmail.com> wrote:
hi guy's
I have a problem with a date format,
I need format a Integer to Date or Integer to String
a example:
int number1 20070101 to date format (01-01-2007)
or
int number1 20070101 to String format (01-01-2007)
number1 is get for method in a DB oracle!!!
greetings°
--
View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com